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
findOrCreate should eagerly load included models. #1711
Comments
Not supported at the moment, probably wouldn't be hard to implement. PR's always welcome. |
I have forked and setup tests, they are running fine. Just a word, for this case the Tests would belong to DAOFactory -> findOrCreate ->
Do they seem right? |
https://github.com/sequelize/sequelize/blob/master/test/dao-factory/create.test.js#L33 ad them here. Your two first cases should already be covered. I'm not sure what case 3 covers but case 4 seems like what you would want to go with for this feature. |
+1 |
1 similar comment
+1 |
This should actually be supported since we changed the signature of |
@mickhansen can you please give an example of a working code with models.Conversation.findOrCreate({
where: {
[ Op.or ]: [
{
recipient_user_id: request.signedinUser.id,
sender_user_id: request.body.user_id
},
{
sender_user_id: request.signedinUser.id,
recipient_user_id: request.body.user_id
}
]
},
include: [
'recipient',
'sender',
models.Chat
],
defaults: {
/* defaults */
}
})
.spread(conversation => {
/* will output undefined */
console.log(conversation.Chats);
console.log(conversation.sender);
console.log(conversation.recipient);
/* will have no Chats, sender or recipient */
console.log(conversation);
}); Eagerloading associations only works when the record exists.
|
I'm having this problem too using v5 beta 15 |
Same |
me too with 4.42.0 |
This is still a problem, why is this issue closed? |
@ccemeraldeyes Can you please provide a SSCCE, many people complained already but no one gave a SSCCE, thanks :) |
@papb I created an SSCCE for you to the best of my ability: https://github.com/createthis/sequelize_1711_sscce |
@createthis Thanks! I will investigate later. |
Still a problem for me in 2020... |
Did anyone get this working? I see the feature is there but it still doesn't seem to be working? |
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
Still happening, not stale. |
db.User.findOrCreate(
{
name: "kam"
},
{ username: "something", email:"something, age:23 },
{
include: [
{ model: db.Language, as: 'learningLanguage' },
{ model: db.Language, as: 'secondaryLanguage' },
{ model: db.Language, as: 'primaryLanguage' }
]
}).success(function (user, created) {
if (created) res.status(201).json(user);
else res.status(200).json(user);
});
I believe this query should create and retuned included models of Language with it? Am I doing something wrong or this is pending.
The text was updated successfully, but these errors were encountered: