question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load/include association for already existing instance

See original GitHub issue

Not sure if this is possible. So I can fetch associations when I am finding object via include:

models.User.find({ where: { id: 1 }, include: [models.Avatar]).then(function(user) {
  user.Avatar // will have avatar object associated with user object.
});

But when I am creating user and use setter to set association, how to get user object in the end to have user.Avatar?

user.setAvatar(avatar).then(function(user) {
  user.Avatar // not defined?
});

Should I always manually assign object after setting relationship?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:45
  • Comments:27 (9 by maintainers)

github_iconTop GitHub Comments

22reactions
felixfbeckercommented, Sep 16, 2016

Please don’t +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features. image

11reactions
ghostoycommented, Apr 14, 2019

I’m shocked that Sequelize doesn’t support this feature. As PHPer before, we benefit this feature provided by Eloquent ORM in Laravel for a long time. I prefer to borrow the load API from Eloquent for loading nested associations with the same queries syntax as Sequelize. For example,

user.load([ { association: 'posts', include: [ 'comments' ] } ]);

Comparing to lazy load mentioned above, it would be easier to load all related associations in one call and optimize the SQL queries as much as possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I seamlessly join my Amazon EC2 Windows ...
Follow these steps to troubleshoot issues when seamlessly joining your Amazon EC2 Windows instance to an AWS Managed Microsoft AD.
Read more >
FormStateInterface.php | Drupal 9.0.x
Name Modifiers Type Overrides FormStateInterface::addBuildInfo public function 2 FormStateInterface::addCleanValueKey public function 2 FormStateInterface::addRebuildInfo public function 2
Read more >
Eager Loading - Sequelize
If an association is aliased (using the as option), you must ... you should instead provide an object with two options: model and...
Read more >
replace-iam-instance-profile-association - Amazon AWS
You can use this action to change the IAM instance profile that's associated with an instance without having to disassociate the existing IAM...
Read more >
Allocate an Amazon Elastic IP and associate it with your ...
Your existing applications will not break because the applications see the IP address they were expecting, even though the back-end EC2 instance has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found