Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timestamps are absent when using limit within include #4740

Closed
bestan opened this issue Oct 27, 2015 · 7 comments
Closed

timestamps are absent when using limit within include #4740

bestan opened this issue Oct 27, 2015 · 7 comments

Comments

@bestan
Copy link

bestan commented Oct 27, 2015

I noticed that timestamps are not passed to the instance when using limit within include (version 3.12.2, postgres).

Example that reproduces the issue:

var Parent = sequelize.define('parent');
var Child = sequelize.define('child');
Parent.hasMany(Child);

//Sync etc.

Parent.create({
  children: [{
    id: 1
  }],
}, {
  include: [Child]
}).then(function(parent) {

  Parent.findAll({
    limit: 5,
    include: [{
      model: Child,
      limit: 5 //Removing limit brings 'created_at' back
    }]
  }).then(function(parents) {
    console.log(parents[0].children[0].created_at); //this is undefined when limit is specified
  });
});

Anything I'm doing wrong here?

@mickhansen
Copy link
Contributor

Sounds odd, can you show the SQL query being run?

@bestan
Copy link
Author

bestan commented Oct 27, 2015

Sure

Executing (default): SELECT "parent"."id", "parent"."created_at", "parent"."updated_at" FROM "parents" AS "parent" LIMIT 5;
Executing (default): SELECT "child".* FROM ((SELECT "id", "created_at", "updated_at", "parent_id" FROM "children" AS "child" WHERE "child"."parent_id" = 1 LIMIT 5)) AS "child";

Running second statement (SELECT "child".* ...) returns all four columns - id, parent_id, created_at and updated_at

@mickhansen
Copy link
Contributor

Odd, don't see any reason why it wouldn't work. Can you try logging parents[0].children[0].dataValues?

@bestan
Copy link
Author

bestan commented Oct 27, 2015

parents[0].children[0].dataValues returns { id: 1, parent_id: 1 }

@mickhansen
Copy link
Contributor

Appears to be a bug with how separate sets the values.

@mickhansen
Copy link
Contributor

Specifically i think we're missing a raw: true.

@bestan
Copy link
Author

bestan commented Oct 27, 2015

@mickhansen confirming that it's fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants