Search code examples
javascriptnode.jsmodelssails.js

Does Sails.js's Models have backreference capability as in Models in Django..?


I am very new to sails.js. Before I have a bit of experience in Django web framework. One of the very beautiful features of django was its model's backreference capabilty.. I was wondering if there was any thing like this in sails.js too..??


Solution

  • Not exactly. But if you look at the waterline-docs you can see that you can do a bit of labour to achieve that functionality. Basically you have to inform the models on both sides to about the relation and the you can use the populate function to retrieve the nested data.. i.e In a one to one relation between User and pet. You can do something like..

    User.findOne().populate('pets'); 
    

    But this obviously is not as cool as django's backreference.. :)