sequelize: Can't save and set associations
Before 1.7 alpha3, i did:
var article = Article.create(),
comment1 = Comment.build(),
comment2 = Comment.build();
article.setComments([comment1, comment2]).done(function () {
// comment1 and comment2 are saved
});
Since 1.7 alpha3, it has changed:
var article = Article.create(),
comment1 = Comment.build(),
comment2 = Comment.build();
article.setComments([comment1, comment2]).done(function () {
// comment1 and comment2 are not saved
});
I must do:
var comment1 = Comment.create(),
comment2 = Comment.create();
But if i do this, i can’t have a strong foreign key constraint on comments.
So, is it a bug ? A feature ? How to do with a strong foreign key constraint ?
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 29 (14 by maintainers)
I dont have time for this. I need something which were suposed to work like creation of nested relationships. your documentation is very bad.
Dude! This is an open source project. You are not paying for it. Either contribute or Have some respect.
we need a better ORM for Node.js this tool are making me crazy and providing me nothing, only headaches.
@jbarros35 👎 contribute or move on.
What happened about the issue ? Is the records adding in db during setting associations ?
@mickhansen Thanks for the reply. I went through the source code and it seems super weird that calling
setAssociation()
will issue a call tosave()
, as you can’t, for example, set multiple associations at once and just issue one INSERT statement.i.e.
belongsTo relations now support
{save: false)
when calling a setter.