-
Notifications
You must be signed in to change notification settings - Fork 99
Diogo doreto query relations #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Extracted SQLConnector.prototype.buildCount from SQLConnector.prototype.count to better test the built SQL.
Node v0.12 doesn't have the Object.assign function
…back-connector into DiogoDoreto-query-relations
That fixes should work. I'm only uncomfortable about the SQL syntax for joins.
Why not:
But I guess if there is no any performance difference between the two options it's OK. What is missing now is the ability to add more complex ORDER BY statement. Right now if there is a where clause of the filter that includes relations, the INNER JOIN is added. But what if I want to order by some field in relation? In that case LEFT OUTER JOIN should be added (if where clouse is not already added INNER one) What do you think? |
We need to make sure that the related model is backed by the same database too. Otherwise |
fe3f993
to
c85c3b9
Compare
@kolach Do you want to further enhance the PR based on your comment? |
@raymondfeng I worked on draft of what I described yesterday in my fork. I have it working now for any deepness of belongsTo relation. Here is a small example: Models:
Now the tests to demo:
To make it work for REST request I had to modify loopback-datasource-juggler. Method:
I commented out all the logic about I can make a PR, for you can review and borrow some parts of the code or ideas for better solution. |
I think one thing that the nested subqueries approach has going for it is that the aliases are scoped to the subquery. So if you need to limit child by grandparent properties, the join to grandparent would not be visible at the SQL query scope of the child. This could help in avoiding duplicate aliases. Consider a query for a child who's mother's father's name is Bob and father's father's name is Steve: In this case, the tables/aliases for mother's father and the father's father don't end up colliding. I do want to point out that when creating aliases, they probably need to be be aliased based on the relation name, not the table name. In the above example, if "mother" and "father" were both relations that lead to an instance in a "person" table, you'd end up writing some bad SQL unless you gave them distinct aliases. If you want to pursue the approach w/o nested subqueries, you'd probably have to generate join aliases based on the path of relationships traversed. So in the above example, you'd have joins aliased as "mother", "father", "mother_father", "father_father" or something like that. Also, I don't like the DISTINCT in the subqueries approach. It causes problems for me in the Postgres connector where there're JSON columns and DISTINCT isn't supported for them because there isn't an equality comparator. Maybe I'm missing something, but I don't quite see why it was deemed necessary in that approach. |
Connect to : #31 Related GH issue: strongloop/loopback#517 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
No description provided.