Skip to main content
Version: v1.1.x

Relationship methods

Relationships methods table

Relation MethodDescriptionParameters
hasMany(Model, foreignKey, localKey)Define a "has many" relationship between the current model and the related model.related: Model or str, foreignKey: str, localKey: str
belongsTo(Model, foreignKey, ownerKey)Define a "belongs to" relationship between the current model and the related model.Model: Model or str, 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 or str, pivotModel: Model or str, 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 or str, throughModel: Model or str, 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

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