Skip to content
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

Closed
1 of 3 tasks
LorenzoRogai opened this issue May 1, 2018 · 6 comments
Closed
1 of 3 tasks

Sorting by deeply associated data #12034

LorenzoRogai opened this issue May 1, 2018 · 6 comments

Comments

@LorenzoRogai
Copy link

LorenzoRogai commented May 1, 2018

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

@LorenzoRogai
Copy link
Author

LorenzoRogai commented May 2, 2018

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?

@ADmad
Copy link
Member

ADmad commented May 2, 2018

What's the association between Articles and Posts? Seems it's hasMany based on your problem description.

@ADmad ADmad added this to the 3.6.3 milestone May 2, 2018
@LorenzoRogai
Copy link
Author

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

@ADmad
Copy link
Member

ADmad commented May 3, 2018

Please provide an actual example which can be used to reproduce your issue, not made up data.

@LorenzoRogai
Copy link
Author

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

@markstory markstory modified the milestones: 3.6.3, 3.6.4 May 13, 2018
@markstory markstory modified the milestones: 3.6.4, 3.6.5 May 21, 2018
@markstory markstory modified the milestones: 3.6.5, 3.6.6 Jun 10, 2018
@markstory markstory modified the milestones: 3.6.6, 3.6.7 Jun 25, 2018
@markstory markstory modified the milestones: 3.6.7, 3.6.8 Jul 8, 2018
@markstory markstory modified the milestones: 3.6.8, 3.6.9, 3.7.0 Jul 24, 2018
@markstory markstory modified the milestones: 3.7.0, Future Dec 9, 2018
@github-actions
Copy link

This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants