Repository navigation
Closed
Description
When using the following options for findAll,
var options = {attributes: ['id', 'title', 'description', 'createdAt', 'price'], order: [['createdAt', 'DESC']], include: [{model: models.User, as: 'user', attributes: userOptions.attributes},
{model: models.Photo, as: 'photos'},
{model: models.Category, as: 'category', attributes: categoryOptions.attributes}]});the query below is produced.
SELECT "Post"."id"
,"Post"."title"
,"Post"."description"
,"Post"."createdAt"
,"Post"."price"
,"user"."id" AS "user.id"
,"user"."email" AS "user.email"
,"photos"."id" AS "photos.id"
,"photos"."post_id" AS "photos.post_id"
,"photos"."createdAt" AS "photos.createdAt"
,"photos"."updatedAt" AS "photos.updatedAt"
,"category"."id" AS "category.id"
,"category"."name" AS "category.name"
FROM "posts" AS "Post"
LEFT JOIN "users" AS "user" ON "Post"."user_id" = "user"."id"
LEFT JOIN "photos" AS "photos" ON "Post"."id" = "photos"."post_id"
LEFT JOIN "categories" AS "category" ON "Post"."category_id" = "category"."id"
ORDER BY "Post"."createdAt" DESC;However, when I add limit:10 to the options, this query is produced instead.
SELECT "Post".*
,"user"."id" AS "user.id"
,"user"."email" AS "user.email"
,"photos"."id" AS "photos.id"
,"photos"."post_id" AS "photos.post_id"
,"photos"."createdAt" AS "photos.createdAt"
,"photos"."updatedAt" AS "photos.updatedAt"
,"category"."id" AS "category.id"
,"category"."name" AS "category.name"
FROM (
SELECT "Post"."id"
,"Post"."title"
,"Post"."description"
,"Post"."createdAt"
,"Post"."price"
FROM "posts" AS "Post"
ORDER BY "Post"."createdAt" DESC LIMIT 10
) AS "Post"
LEFT JOIN "users" AS "user" ON "Post"."user_id" = "user"."id"
LEFT JOIN "photos" AS "photos" ON "Post"."id" = "photos"."post_id"
LEFT JOIN "categories" AS "category" ON "Post"."category_id" = "category"."id"
ORDER BY "Post"."createdAt" DESC;This produces an sql error as the innermost select will not contain any of the foreign keys referenced in the joins.
Is there any way to select all columns in the inner query, and then trim in the outer?
Activity
mickhansen commentedon Mar 11, 2015
What version of sequelize? I believe we've covered most of these issues by now.
Would be helpfull to see your model definitions and relation setups.
waltonseymour commentedon Mar 11, 2015
I am using sequelize 2.0.0
Here's the Post model definition. Let me know if you need the others.
The associations are created by calling:
mickhansen commentedon Mar 12, 2015
Have you tried the latest version?
waltonseymour commentedon Mar 12, 2015
Just updated to 2.0.4. Same issue persists.
mickhansen commentedon Mar 12, 2015
Looks like a bug then.
mickhansen commentedon Mar 30, 2015
@bobdye there's generally poor support for aggregates and includes at the moment.