Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Enable and honour query parameters to include/exclude relationships and properties #20

Closed
mgenev opened this issue Mar 6, 2015 · 7 comments

Comments

@mgenev
Copy link

mgenev commented Mar 6, 2015

This question actually popped up in the sane gitter chat and I was thinking of how to accomplish it so I'm glad to see in the road map. I found this issue:
balderdashy/sails#780 (comment)

So according to this the 2nd param in the find can let us accomplish this, if it is recognized by the blueprint and passed properly.

I did something similar by adding a basic mongo $near query to the old version of your blueprint which you can see here what I did to the_actionUtil:
mgenev/how-to-sane@8a27ebc

Ignore the changes to the find.js, that was from an early attempt and made unnecessary by adding to the criteria in the action util, so the latest version of find is as you wrote it:
https://github.com/mgenev/how-to-sane/blob/master/server/api/blueprints/find.js

This has allowed me to do geoQueries from Ember like this:
https://github.com/mgenev/how-to-sane/blob/master/client/app/pods/s/vendors/index/route.js#L8-L15

I'm not sure how you planned to go about the issue of including or omitting properties, but it seemed to me like this approach can work. Also if you can comment on what you think of the geo implementation that would be great. I want to add solid mongo support and I believe postGIS can allow that in PostgreSQL as well.

@mphasize
Copy link
Owner

mphasize commented Mar 6, 2015

Internally Waterline is also using a select option in the query, see here https://github.com/balderdashy/waterline/blob/master/lib/waterline/query/integrator/JOIN_INSTRUCTIONS.md

I think that getting the parameters and passing them to Waterline will probably be one of the lesser problems. I assume that the harder part will be to protect against injections, white-list the selectable columns and all that stuff.

I will take a look at the geo stuff, but unfortunately I don't have anything related to geodata on my machine atm, so I won't be able to play around with it.

@crunchtime-ali
Copy link

I think that protection against injection, whitelisting etc. should be handled at model-level on the Sails-side. As you already stated it will be complicated to handle it at blueprint-level.

Having some mechanism to decorate models (define a subset of their properties) and being able to bind such subsets to policies etc. would be totally handy to achieve the effect.

@crunchtime-ali
Copy link

Hey @mphasize, I basically need this feature to decrease the size of my JSON responses. Therefore protecting it would not be required.

For example:
In my post-model I got the full Markdown-text, a parsed representation of the post and a parsed excerpt.
In my admin-backend I'd only need to retrieve the markdown-text, on a single blogpost page I'd need the full parsed post and everywhere else just the excerpt.

I think this would be a great use-case for the advanced blueprints.

@mphasize
Copy link
Owner

mphasize commented Apr 1, 2015

Agreed that it's a great use case. Are you thinking of starting a PR for this?

@mgenev
Copy link
Author

mgenev commented Apr 7, 2015

@mphasize i'm opening this up for discussion in the sane gitter, let's hope we come up with something as a team effort and pull it off quickly

@mgenev
Copy link
Author

mgenev commented Apr 7, 2015

Saving these issues for reference https://github.com/balderdashy/waterline/issues/266 balderdashy/waterline#509 which @Globegitter says are prerequisites for a clean solution

@crunchtime-ali
Copy link

balderdashy/waterline#952 replaces balderdashy/waterline#509.
.pick() and omit() are supposed to land in 0.11 (if it is every released).
I wouldn't bother waiting for https://github.com/balderdashy/waterline/issues/266 as using pick() and omit() will be sufficient for most.

@mphasize mphasize closed this as completed Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants