returningProperties method Null safety

  1. @override
void returningProperties(
  1. List propertyIdentifiers(
    1. InstanceType x
    )
)
override

Configures the list of properties to be fetched for InstanceType.

This method configures which properties will be populated for InstanceType when returned from this query. This impacts all query execution methods that return InstanceType or List of InstanceType.

The following example would configure this instance to fetch the 'id' and 'name' for each returned 'Employee':

    var q = Query<Employee>()
      ..returningProperties((employee) => [employee.id, employee.name]);

Note that if the primary key property of an object is omitted from this list, it will be added when this instance executes. If the primary key value should not be sent back as part of an API response, it can be stripped from the returned object(s) with ManagedObject.removePropertyFromBackingMap.

If this method is not invoked, the properties defined by ManagedEntity.defaultProperties are returned.

Implementation

@override
void returningProperties(
  List<dynamic> Function(InstanceType x) propertyIdentifiers,
) {
  final properties = entity.identifyProperties(propertyIdentifiers);

  if (properties.any(
    (kp) => kp.path.any(
      (p) =>
          p is ManagedRelationshipDescription &&
          p.relationshipType != ManagedRelationshipType.belongsTo,
    ),
  )) {
    throw ArgumentError(
      "Invalid property selector. Cannot select has-many or has-one relationship properties. Use join instead.",
    );
  }

  _propertiesToFetch = entity.identifyProperties(propertyIdentifiers);
}