|
| 1 | +```dart |
1 | 2 | //.title |
2 | 3 | // ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ |
3 | 4 | // |
|
15 | 16 | // ignore_for_file: unnecessary_null_comparison |
16 | 17 | // ignore_for_file: unnecessary_question_mark |
17 | 18 |
|
18 | | -// This line is not actually in the generated code. |
19 | | -import 'package:df_generate_dart_models_core/df_generate_dart_models_core.dart'; |
20 | | - |
21 | | -// This line is in the generated code. |
22 | | -//part of 'field_model.dart'; |
| 19 | +part of 'example.md'; |
23 | 20 |
|
24 | 21 | // ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
25 | 22 |
|
26 | 23 | /// Generated class for [_FieldModel]. |
27 | | -class FieldModel extends Model { |
| 24 | +class FieldModel extends _FieldModel { |
28 | 25 | // |
29 | 26 | // |
30 | 27 | // |
@@ -337,65 +334,6 @@ class FieldModel extends Model { |
337 | 334 | } |
338 | 335 | } |
339 | 336 |
|
340 | | - @override |
341 | | - T mergeWith<T extends BaseModel>( |
342 | | - BaseModel? other, { |
343 | | - bool deepMerge = false, |
344 | | - }) { |
345 | | - final a = toJson(); |
346 | | - final b = other?.toJson() ?? {}; |
347 | | - final data = (deepMerge ? mergeDataDeep(a, b) : {...a, ...b}) as Map; |
348 | | - return FieldModel.fromJson(data.cast()) as T; |
349 | | - } |
350 | | - |
351 | | - /// Creates a copy of this instance, replacing the specified fields. |
352 | | - static FieldModel copyWith( |
353 | | - FieldModel src, { |
354 | | - List<String>? fieldPath, |
355 | | - dynamic? fieldType, |
356 | | - bool? nullable, |
357 | | - List<Map<String, dynamic>>? children, |
358 | | - bool? primaryKey, |
359 | | - bool? foreignKey, |
360 | | - Object? fallback, |
361 | | - String? description, |
362 | | - }) { |
363 | | - return FieldModel.assertRequired( |
364 | | - fieldPath: fieldPath ?? src.fieldPath, |
365 | | - fieldType: fieldType ?? src.fieldType, |
366 | | - nullable: nullable ?? src.nullable, |
367 | | - children: children ?? src.children, |
368 | | - primaryKey: primaryKey ?? src.primaryKey, |
369 | | - foreignKey: foreignKey ?? src.foreignKey, |
370 | | - fallback: fallback ?? src.fallback, |
371 | | - description: description ?? src.description, |
372 | | - ); |
373 | | - } |
374 | | - |
375 | | - /// Creates a copy of this instance, removing the specified fields. |
376 | | - static FieldModel copyWithout( |
377 | | - FieldModel src, { |
378 | | - bool fieldPath = true, |
379 | | - bool fieldType = true, |
380 | | - bool nullable = true, |
381 | | - bool children = true, |
382 | | - bool primaryKey = true, |
383 | | - bool foreignKey = true, |
384 | | - bool fallback = true, |
385 | | - bool description = true, |
386 | | - }) { |
387 | | - return FieldModel.assertRequired( |
388 | | - fieldPath: fieldPath ? src.fieldPath : null, |
389 | | - fieldType: fieldType ? src.fieldType : null, |
390 | | - nullable: nullable ? src.nullable : null, |
391 | | - children: children ? src.children : null, |
392 | | - primaryKey: primaryKey ? src.primaryKey : null, |
393 | | - foreignKey: foreignKey ? src.foreignKey : null, |
394 | | - fallback: fallback ? src.fallback : null, |
395 | | - description: description ? src.description : null, |
396 | | - ); |
397 | | - } |
398 | | - |
399 | 337 | /// Returns the value of the [fieldPath] field. |
400 | 338 | /// If the field is nullable, the return value may be null; otherwise, it |
401 | 339 | /// will always return a non-null value. |
@@ -472,3 +410,66 @@ abstract final class FieldModelFieldNames { |
472 | 410 | /// The field name of [FieldModel.description]. |
473 | 411 | static const description = 'description'; |
474 | 412 | } |
| 413 | +
|
| 414 | +extension FieldModelX on FieldModel { |
| 415 | + /// Creates a copy of this instance, merging another model's fields into |
| 416 | + /// this model's fields. |
| 417 | + FieldModel mergeWith( |
| 418 | + BaseModel? other, { |
| 419 | + bool deepMerge = false, |
| 420 | + }) { |
| 421 | + final a = toJson(); |
| 422 | + final b = other?.toJson() ?? {}; |
| 423 | + final data = (deepMerge ? mergeDataDeep(a, b) : {...a, ...b}) as Map; |
| 424 | + return FieldModel.fromJson(data.cast()); |
| 425 | + } |
| 426 | +
|
| 427 | + /// Creates a copy of this instance, replacing the specified fields. |
| 428 | + FieldModel copyWith( |
| 429 | + FieldModel src, { |
| 430 | + List<String>? fieldPath, |
| 431 | + dynamic? fieldType, |
| 432 | + bool? nullable, |
| 433 | + List<Map<String, dynamic>>? children, |
| 434 | + bool? primaryKey, |
| 435 | + bool? foreignKey, |
| 436 | + Object? fallback, |
| 437 | + String? description, |
| 438 | + }) { |
| 439 | + return FieldModel.assertRequired( |
| 440 | + fieldPath: fieldPath ?? this.fieldPath, |
| 441 | + fieldType: fieldType ?? this.fieldType, |
| 442 | + nullable: nullable ?? this.nullable, |
| 443 | + children: children ?? this.children, |
| 444 | + primaryKey: primaryKey ?? this.primaryKey, |
| 445 | + foreignKey: foreignKey ?? this.foreignKey, |
| 446 | + fallback: fallback ?? this.fallback, |
| 447 | + description: description ?? this.description, |
| 448 | + ); |
| 449 | + } |
| 450 | +
|
| 451 | + /// Creates a copy of this instance, removing the specified fields. |
| 452 | + FieldModel copyWithout( |
| 453 | + FieldModel src, { |
| 454 | + bool fieldPath = true, |
| 455 | + bool fieldType = true, |
| 456 | + bool nullable = true, |
| 457 | + bool children = true, |
| 458 | + bool primaryKey = true, |
| 459 | + bool foreignKey = true, |
| 460 | + bool fallback = true, |
| 461 | + bool description = true, |
| 462 | + }) { |
| 463 | + return FieldModel.assertRequired( |
| 464 | + fieldPath: fieldPath ? this.fieldPath : null, |
| 465 | + fieldType: fieldType ? this.fieldType : null, |
| 466 | + nullable: nullable ? this.nullable : null, |
| 467 | + children: children ? this.children : null, |
| 468 | + primaryKey: primaryKey ? this.primaryKey : null, |
| 469 | + foreignKey: foreignKey ? this.foreignKey : null, |
| 470 | + fallback: fallback ? this.fallback : null, |
| 471 | + description: description ? this.description : null, |
| 472 | + ); |
| 473 | + } |
| 474 | +} |
| 475 | +``` |
0 commit comments