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

Attaches sibling to this model using the given relationship type.
detach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Detaches sibling from this model using the given relationship type.
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.