balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

[Proposal] Support projections in 1 to 1 populates as a subquery #4167

Closed Josebaseba closed 7 years ago

Josebaseba commented 7 years ago

Sails version: 1 Node version: 8 NPM version: 3 Operating system: All


Hi guys,

This is just a feature that I think that could be super useful in a lot of different scenarios. As you know now we can do a subcriteria query in a populate 1:N or N:M types. If you try to do a subcriteria query in a 1:1 relationship you'll see a nice error and that's ok.

But, I think that a projection subcriteria would be very useful:


// Classwall messages by classroom

ClasswallMessages
    .find({classroom: classroomId})
    .populate('student', {select: ['id', 'name']})
    .populate('teacher', {select: ['id', 'nickname', 'email']})
    .exec(console.log);

I know that we have the customToJSON method, but sometimes we need to select more specific attributes only.

Thanks!

sailsbot commented 7 years ago

@Josebaseba Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

sgress454 commented 7 years ago

@Josebaseba we're with you -- this is tracked in this Trello card, and the error message you mentioned has been updated to mention that it's in the works.

Josebaseba commented 7 years ago

Nice!