How to combine basic where clause and include where clause

38 views
Skip to first unread message

Julien Musat

unread,
Apr 29, 2015, 5:48:14 AM4/29/15
to sequ...@googlegroups.com
Hello,

Here is what I'm trying to do :

app.models.restaurant.findAll(
{
where: {id: restaurantIds}
},
{
include: [{
model: app.models.food_type, 
where: {id: 2} ,
through: {attributes: []}
}]
});

I have first where clause on restaurant, and a second where clause on food_type which is related with a Many to Many relation that works fine.

If I query each where clause separately it works. But when combined, the where clause in include is ignored

Julien Musat

unread,
Apr 29, 2015, 5:51:13 AM4/29/15
to sequ...@googlegroups.com
Moreover, if I change I place include before where clause on restaurant, the where clause on restaurant is ignored

Mick Hansen

unread,
Apr 29, 2015, 5:58:52 AM4/29/15
to Julien Musat, sequ...@googlegroups.com
Ignored how?
There's really no case where `include.where` is ignored.

You might be looking for: https://github.com/sequelize/sequelize/issues/3095
--
Mick Hansen
@mhansendev
mhansen.io

Julien Musat

unread,
Apr 29, 2015, 6:02:08 AM4/29/15
to sequ...@googlegroups.com, julien...@gmail.com
Actually, the whole include option is ignored when placed after the where clause on restaurant

Julien Musat

unread,
Apr 29, 2015, 6:03:26 AM4/29/15
to sequ...@googlegroups.com, julien...@gmail.com
I've just found a workaround :

app.models.restaurant.findAll(
{
include: [{
model: app.models.food_type, 
where: ['restaurant.id IN(?) and food_types.id = ?', restaurantIds, 2],
through: {attributes: []}
}]
}
);
Reply all
Reply to author
Forward
0 new messages