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
Sorting by deeply associated data #12034
Comments
It does work by adding ->innerJoinWith('Users.Articles.Posts') But does this additional innerJoin import the same data 2 times? Main query inner join + containable subquery? |
What's the association between |
It was only an example but they are all associated with hasOne, only the last one. "Posts" in this case, have a condition inside the table definition |
Please provide an actual example which can be used to reproduce your issue, not made up data. |
Actually i can't share these data, however this a general issue on all queries You can create a 3 level associated tables to reproduce the problem 1 > 2 > 3 You can try to sort up to first and second level columns names but from the third it doesn't work anymore |
This issue is stale because it has been open for 120 days with no activity. Remove the |
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 3.6.2
What you did
Tried to order by a deeply associated table
What happened
Even though the tables are defined with belongsTo and hasOne associations type CakePHP use subqueries on the deep levels to get the data and the fields we need to order are not present in the main query
Example:
Users.Articles.Posts
If i try to order by Articles.id it works fine because Articles is present as an INNER JOIN in the query
But ordering with Users.Articles.Posts.id (also tried with Articles.Posts.id, Posts.id) doesn't work because the Posts are being retrieved using a separate query
What you expected to happen
Could be useful to have a way to force it to use a single query so the ORDER BY clause will work or improve the documentation if there is already a way to do this
Thank you
The text was updated successfully, but these errors were encountered: