node.js - hasMany relation: including from the other direction -
say have next model:
user.json: {//... "relations":{ "invoices": { "type": "hasmany", "model": "invoice", "foreignkey": "receiverid" }, } //... } a.k.a. user might have many invoices. code adds field receiverid invoice model.
now want list of invoices including receivers. how can that?
invoice.find({include: "reciever"}) or
invoice.find({include: "user"}) did not work, returned: "relation \"receiver\" not defined invoice model" error.
thanks help.
you have define belongsto relation in invoice model.
invoice.json:
{//... "relations":{ "receiver": { "type": "belongsto", "model": "receiver" }, } //... } then can query model this:
invoice.find({include: "receiver"}, function(data){ console.log(data); });
Comments
Post a Comment