I'm using the ORM2 module (https://github.com/dresende/node-orm2) for Node.js and it seems to work fine, but I can't figure out a way to associate two records that are related.
Here is my problem:
I have entityA which has many entityB elements (a simple hasMany relationship), now.. how can I save a record of entityA type and associate it with many entityB type records? Has anyone done that with this module before?
Ok, thanks to @dmahapatro's recommendation, I found a method called "addEntity2s()" (following his example) which takes care of associating both records.
It should work something like this: (Say we have an array of ids to be associated with a new record)
var modelBs = [1,2,3,4]; //ids of records of type modelB
modelA.create([{field1:"data", field2:"more data"}], function(err, models) {
modelB.find({id:modelBs}, function(err, modelBInstances){
models[0].addModelB(modelBInstances);
});
});
There is probably a better way, but that's the way I found made it work.