ModelRelationshipOps extension
Relationship mutation and eager-loading helpers attached to Model.
These helpers support attaching and detaching related models and building loaded JSON payloads that include relationship data.
Example:
await user.attach(
role,
relationship: ModelRelationshipType.belongsToMany,
table: userRolesPivot,
);
- on
Methods
-
attach(
Model sibling, {required ModelRelationshipType relationship, PivotTable< Model, Model> ? table, DatabaseDisk disk = Model.defaultDisk}) → Future<bool> -
Available on Model, provided by the ModelRelationshipOps extension
Attachessiblingto this model using the givenrelationshiptype. -
detach(
Model sibling, {required ModelRelationshipType relationship, PivotTable< Model, Model> ? table, DatabaseDisk disk = Model.defaultDisk}) → Future<bool> -
Available on Model, provided by the ModelRelationshipOps extension
Detachessiblingfrom this model using the givenrelationshiptype. -
load<
T extends Model> (ModelRelationshipType relationship, {PivotTable< Model, Model> ? table}) → Future<Map< String, dynamic> > -
Available on Model, provided by the ModelRelationshipOps extension
Loads a relationship and returns this model serialized with the related data embedded.