Relationships
Relationships
Method | Description | Parameters |
---|---|---|
hasOne(model, foreignKey, localKey) | Define a "has one" relationship between the current model and the related model. | model: Model , foreignKey: str , localKey: str |
hasMany(model, foreignKey, localKey) | Define a "has many" relationship between the current model and the related model. | model: Model , foreignKey: str , localKey: str |
belongsTo(model, foreignKey, ownerKey) | Define a "belongs to" relationship between the current model and the related model. | model: Model , foreignKey: str , ownerKey: str |
belongsToMany(model, pivotModel, foreignKey, foreignKeyTarget) | Define a "belongs to many" relationship between the current model and the related model through a pivot collection. | model: Model , pivotModel: Model , foreignKey: str , foreignKeyTarget: str |
hasManyThrough(model, throughModel, foreignKey, throughForeignKey) | Define a "has many through" relationship between the current model and the related model through a pivot Model. | model: Model , throughModel: Model , foreignKey: str , throughForeignKey: str |
with(relation, options?) | To perform eager loading of specified relationship. | relation: str , options: obj |
has(relation, options?) | Alias for the with method. | relation: str , options: obj |
attach(ids) | Attach one or more models to the parent model. | ids: id or id[] |
detach(ids) | Detach one or more models from the parent model. | ids: id or id[] |
sync(ids) | Sync the intermediate collections with a list of IDs. | ids: id or id[] |
Polymorphic Relationships
Method | Description | Parameters |
---|---|---|
morphTo(model, relation) | Establishes a polymorphic "morph to" relationship. | model: Model , relation: str |
morphMany(model, relation) | Define a polymorphic one-to-many relationship. | model: Model , relation: str |
moprhToMany(model, relation) | Define a polymorphic many-to-many relationship. | model: Model , relation: str |
morphedByMany(model, relation) | Define a polymorphic many-to-many relationship. | model: Model , relation: str |
Support us
Mongoloquent is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.
Sponsors
_