Reputation: 557
jugglingdb exposes two functions to create relational dbs: belongsTo and hasMany
i now aks myself how i might use this in daily development.
belongsTo and hasMany are adding functions to the objects, but as it seems there is no way to create relations between existing objects?
see: http://compoundjs.com/juggling.html#hasMany for an example.
i would like to not create the object but instead create linkages between existing objects, how will that work?
maybe i am just misinterpreting the functions?
have fun
jascha
ps: would be great if someone with 1500+ rep could create the jugglingdb tag and add it to this question? i really cant say if its relevant enough though.
Upvotes: 2
Views: 833
Reputation: 307
When you, i.e. want to add articles for an existing author, you can do it like the following:
User.find(uid, function(err, user) {
var article = user.articles.build({articleName : 'Article Foo'});
article.save();
});
That will automatically create a foreign key for user inside the new created article.
Upvotes: 3