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

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -