Here is my rule of thumb: I think objects, not object identifiers.
var post = // ... this is a real object, not an id. it can be new var comment = // ... this is a real object, not an id. it can be new // posts might have many comments by keeping an array of pointers called "comments" post.add("comments", comment); // or posts might have many comments by keeping a relation called "comments" post.relation("comments").add(comment);
After that, the parent side of the relationship can be saved, as well as unsaved children:
post.save().then(function(savedPost) {
danh
source share