fieldsIncludingInherited property

List<SerializableModelFieldDefinition> get fieldsIncludingInherited

Returns a list of all fields in this class, including inherited fields. It ensures that the 'id' field, if present, is always included at the beginning of the list.

Implementation

List<SerializableModelFieldDefinition> get fieldsIncludingInherited {
  bool hasIdField = fields.any((element) => element.name == 'id');

  return [
    if (hasIdField) fields.firstWhere((element) => element.name == 'id'),
    ...inheritedFields,
    ...fields.where((element) => element.name != 'id'),
  ];
}