Repository navigation
Description
What are you doing?
I have a problem with nested includes, I have the following class methods which performs a findAll:
Video.getVideos = function(limit, offset, sort) {
return Video.findAll({
attributes: ['id', 'createdAt', 'name', 'description'],
limit: limit,
offset: offset,
order: Video.getFilterOrder(sort),
where: {
[Op.or]: [{
channelId: 's7591665',
}, {
privacy: 'public',
}, {
privacy: 'private',
[Op.or]: [{
'$videoACL.id$': 'MOCK_USER_ID',
'$videoACL.type$': 'USER',
}, {
'$videoACL.id$': {
[Op.in]: [], // mock user groups, currently none
},
'$videoACL.type$': 'AD_GROUP',
}],
}, {
privacy: 'channel',
[Op.or]: [{
'$channel.channelACL.id$': 'MOCK_USER_ID',
'$channel.channelACL.type$': 'USER',
}, {
'$channel.channelACL.id$': {
[Op.in]: [], // mock user groups, currently none
},
'$channel.channelACL.type$': 'AD_GROUP',
}],
},
],
},
include: [{
model: models.VideoAccess,
as: 'videoACL',
required: false,
attributes: [],
// duplicating: false, // pg sequelize bug: https://github.com/sequelize/sequelize/issues/8432
}, {
model: models.Channel,
as: 'channel',
required: false,
attributes: ['id', 'name'],
// duplicating: false, // pg sequelize bug: https://github.com/sequelize/sequelize/issues/8432
include: [{
model: models.ChannelAccess,
as: 'channelACL',
attributes: [],
// duplicating: false, // pg sequelize bug: https://github.com/sequelize/sequelize/issues/8432
required: false,
}],
}],
});
};
Video.getVideosScoped = function(limit, offset, sort) {
return Video.scope({ method: ['authorized', 'MOCK_USER_ID', []] }).findAll({
attributes: ['id', 'createdAt', 'name', 'description'],
limit: limit,
offset: offset,
order: Video.getFilterOrder(sort),
include: [{
model: models.Channel,
as: 'channel',
required: false,
attributes: ['id', 'name'],
// duplicating: false, // pg sequelize bug: https://github.com/sequelize/sequelize/issues/8432
}],
});
};Basically Video.getVideosScoped() does the same as Video.getVideos() , only by using a scope, which is querying the videos the user (Channel) has access to. The attempt to move to scope, is realizing this query would be probably very common in my app.
The bug is actually a twofold:
- Using
Video.getVideos()generates the error in the title, unless addingduplicating: falseas explained in issue Sequelize generating: missing FROM-clause entry for table #8432 (though to be honest, I still don't understand if this is a bug or usage requirement). - Using
Video.getVideosScoped(), with or withoutduplicating: false(in the scope query, or the query itself, or both), doesn't seem to solve the issue.
I've search for more similar issues, all became stale. Limit causing "missing FROM-clause entry for table" #4446 suggests the problem is with thelimit, I've tried to remove it, but still no luck.
Finally, my model definitions and associations are in this gist.
What do you expect to happen?
The query to be executed, basically what I'm trying to do is query all videos the user has access to, including the video's channel.
What is actually happening?
Getting error: error: missing FROM-clause entry for table "videoACL", The actual table may be different according to each scenario I described.
Output, either JSON or SQL
'SELECT "Video".*, "channel"."id" AS "channel.id", "channel"."name" AS "channel.name" FROM (SELECT "Video"."id", "Video"."createdAt", "Video"."name", "Video"."description" FROM "Videos" AS "Video" WHERE ("Video"."channelId" = \'s7591665\' OR "Video"."privacy" = \'public\' OR ((("videoACL"."id" = \'s7591665\' AND "videoACL"."type" = \'USER\') OR ("videoACL"."id" IN (NULL) AND "videoACL"."type" = \'AD_GROUP\')) AND "Video"."privacy" = \'private\') OR ((("channel->channelACL"."id" = \'s7591665\' AND "channel->channelACL"."type" = \'USER\') OR ("channel->channelACL"."id" IN (NULL) AND "channel->channelACL"."type" = \'AD_GROUP\')) AND "Video"."privacy" = \'channel\')) AND "Video"."published" = true ORDER BY RANDOM() LIMIT 12 OFFSET 0) AS "Video" LEFT OUTER JOIN "VideoAccesses" AS "videoACL" ON "Video"."id" = "videoACL"."VideoId" LEFT OUTER JOIN "Channels" AS "channel" ON "Video"."channelId" = "channel"."id" LEFT OUTER JOIN "ChannelAccesses" AS "channel->channelACL" ON "channel"."id" = "channel->channelACL"."ChannelId" ORDER BY RANDOM();'Dialect: postgress
Dialect version: [email protected]
Database version: Postgress 9.6
Sequelize version: [email protected]
Tested with latest release: Yes, see above.
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
Activity
papigers commentedon Sep 5, 2018
Please help... I've tried to upgrade to v5.10 to see if this fixes the problem but no luck...
sushantdhiman commentedon Sep 8, 2018
Moved to #9869