A field-type for Mongoose schemas that allows easy relationships between models.
This field-type will populate external model references. If you update either side of the the relationship, it will update it on both.
var mongoose = ;var Relation = ;
The module exports it's field-type, but also adds it to
mongoose.SchemaTypes.Relation, like other fieldtypes.
var UserSchema =authored: type:Relation ref:'Post' fieldref: 'author'edited: type:Relation ref:'Post' fieldref:'editors';var User = mongoose;var PostSchema =author: type:Relation ref:'User'editors: type:Relation ref:'User';var Post = mongoose;
In this example, if you add Posts to
User.authored, they will be added to the Post's corresponding fields and vice-versa. You still need to save all the records involved.
You should always add relationships with the whole object:
var post = ;var author = ;var editor1 = ;var editor2 = ;postauthor = author;posteditors = editor1 editor2;
_id triggers "manual mode", meaning that you are manually managing the relationship (like standard mongoose
Have a look at the tests for more examples.
Since ths uses standard mongoose references over
ObjectIds, you can fill record's children with