Populate, add and remove in Sails v0.11.0

131 views
Skip to first unread message

Erk

unread,
Feb 11, 2015, 10:46:23 AM2/11/15
to sai...@googlegroups.com
Hi!

Just installed the new release. Was really looking forward to this one! Thanks!!!

However, where did the populate, add and remove blueprints go? Take this User model:

module.exports = {
  attributes
: {
    name
: {
      type
: 'string'
   
},
    pets
: {
      collection
: 'pet',
      via
: 'id'
   
},
    favoritePet
: {
      model
: 'pet',
      via
: 'id'
   
}
 
}
};

Now create a user, some pets (pets just have a name attribute) and a favoritePet. As opposed to v0.10.5, the following routes give a 404 error:
  • GET /user/1/pets
  • POST /user/1/pets
  • DELETE /user/1/pets
  • GET /user/1/favoritePet
  • and so on
Why have these blueprints been omitted? We should cover that in the migration guide...

In the meantime, this is how to restore functionality with custom routes:
'GET /user/:id/pets' : {model: 'user', blueprint: 'populate', alias: 'pets'},
'POST /user/:parentid/pets' : {model: 'user', blueprint: 'add', alias: 'pets'}
and so on...

However, a lot of the cool Sails magic went missing... or did I miss an important point here?

Erk

unread,
Feb 12, 2015, 4:33:54 AM2/12/15
to sai...@googlegroups.com
Edit:

DELETE rout should look like this:
  • DELETE /user/1/pets/1
Custom routes should look like this:
'GET /user/:parentid/pets' : {model: 'user', blueprint: 'populate', alias: 'pets'},

Erk

unread,
Feb 12, 2015, 5:10:51 AM2/12/15
to sai...@googlegroups.com
The above routes bypass any policies. You can either use
[{policy: 'auth'}, {policy: 'auth2'}, {model: 'user', blueprint: 'populate', alias: 'pets'}]
syntax or treat blueprints as actions like in
{controller: 'UserController', action: 'populate', alias: 'pets'}

Erk

unread,
Feb 13, 2015, 1:48:03 PM2/13/15
to sai...@googlegroups.com
OK, I created a repository for this one.


Can someone please take a look? It works in v0.10.5 but not on v0.11.0. Thanks!

Erk

unread,
Feb 17, 2015, 5:49:54 AM2/17/15
to sai...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages