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

Fix Model::first() only use orderBy() when group by is not empty #2907

Merged
merged 13 commits into from
May 1, 2020

Conversation

samsonasik
Copy link
Member

This fix the condition, eg: in Postgresql when we can supply sql like:

SELECT SUM(id) as total FROM "user" WHERE 1 = 1 LIMIT 1 ;

without group by, and followed order by. So, make order by only when there is a group by.

Checklist:

  • Securely signed commits
  • Unit testing, with >80% coverage

@samsonasik samsonasik force-pushed the bug-fix-first-group-by branch from aa9b85e to 31ce7de Compare April 30, 2020 20:11
@samsonasik samsonasik force-pushed the bug-fix-first-group-by branch from c01f554 to 7d515e5 Compare April 30, 2020 20:50
@samsonasik
Copy link
Member Author

It seems "group by" resetted on query builder limit call. it require a deep check.

@samsonasik samsonasik changed the title Fix Model::first() only use orderBy() when group by is not empty [wip] Fix Model::first() only use orderBy() when group by is not empty Apr 30, 2020
@samsonasik samsonasik changed the title [wip] Fix Model::first() only use orderBy() when group by is not empty Fix Model::first() only use orderBy() when group by is not empty May 1, 2020
@samsonasik
Copy link
Member Author

Fixed. On withDeleted()->first(), it requires to group by primary key when there is no group by clause.

@samsonasik
Copy link
Member Author

It seems not really working if Model::useSoftDeletes is false.

@samsonasik
Copy link
Member Author

samsonasik commented May 1, 2020

added check force group by only when Model::useSoftDeletes is true with withDeleted() call.

@samsonasik
Copy link
Member Author

travis build green 🎉

@lonnieezell lonnieezell merged commit 734edb4 into codeigniter4:develop May 1, 2020
@samsonasik samsonasik deleted the bug-fix-first-group-by branch May 1, 2020 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants