Re: findAndCountAll not working when using include on Belongs to many realtion

261 views
Skip to first unread message

Mick Hansen

unread,
May 6, 2015, 7:08:14 AM5/6/15
to Julien Musat, sequ...@googlegroups.com
Querying nested resources like that is generally not supported.
You need to use `include.where` or wait for the upcoming nested querying feature (without it being on join), no ETA though.

On Wed, May 6, 2015 at 10:50 AM, Julien Musat <julien...@gmail.com> wrote:
Hi,

I have a working belongs to many relation on restaurant and food_type via restaurant_has_food_type.

I can query restaurant with findAll without problem.

But when I'm using findAndCountAll :

_models.restaurant.findAndCountAll( {
          include: [{
            model: _models.food_type,          
            through: {attributes: []}
          }],
          where: [
            'food_type.id IN(1,2)'
          ],
            offset: offset,
            limit: limit
        });
      

This generate the following sql : 

Executing (default): SELECT count(*) AS `count` FROM `restaurant` AS `restaurant
` WHERE food_type.id IN(1,2);
error: SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Champ 'food_type.id' inconnu
dans where clause








--
Mick Hansen
@mhansendev
mhansen.io
Reply all
Reply to author
Forward
0 new messages