ianhaggerty / backbone-sails

A plugin for Backbone that makes integrating with Sails JS easier. Both leverage a model-view architecture, it's only natural to have them talk to each other.
MIT License
7 stars 1 forks source link

Populating a nested association #7

Closed dottodot closed 9 years ago

dottodot commented 9 years ago

I have the following Comment model with a user association, but is it possible to populate the user on the child collection or would it require modifying the blueprint to achieve this?

module.exports = {
  attributes: {
    comment: 'string',
    parent: {
        model: 'Comment'
    },
    children: {
        collection: 'Comment',
        via: 'parent'
    },
    user: {
        model: 'User'
    }
  }
};
ianhaggerty commented 9 years ago

Sails doesn't support 'nested' populations. It wouldn't be too difficult to code on the server side, but the security considerations are endless. It would take two round-trips to the database in any case (through waterline).

Your better off just getting the model & populating:

coll.get("children", true).findWhere({ name: "Haggerty" }).populate(true).fetch();