I am coming from Laravel where you can work with Eloquent. In Eloquent you can do something like:
$this->hasOne('App\Models\Member', 'family_id')->where('relation', '=', 1);
In order to get a specific member within a wider scope.
Is the same thing possible to do in Sequelize? I see I can do
Family.hasMany(models.Member);
or
Family.hasOne(models.Member);
but I don't see where I Can add a constraint. Any ideas?
In order to accomplish this. The where clause is moved to the controller and not predefined in the model. It would be done like this:
models.Family.findAll({
include:[
{
model : models.Member,
where: {relation : 1}
},
]
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.