CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

Adds a when() method to the query builder.

Open lonnieezell opened this issue 1 year ago • 11 comments

Description

This adds a method, when() to the Query Builder that can conditionally modify queries based on the truthiness of a given condition.

Checklist:

  • [X] Securely signed commits
  • [x] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [x] Unit testing, with >80% coverage
  • [ ] User guide updated
  • [x] Conforms to style guide

lonnieezell avatar Aug 02 '22 05:08 lonnieezell

This is an enhancement, so it should go to 4.3 branch, not develop.

kenjis avatar Aug 02 '22 05:08 kenjis

@lonnieezell Only changing the base branch on GitHub will not work. Because you created the PR branch based on develop.

Even if you rebase, if there are commits that have not been merged into 4.3, the PR branch will contain them.

The easy way is to create a new branch from 4.3 and cherry-pick commits that are needed.

kenjis avatar Aug 03 '22 05:08 kenjis

@kenjis , this is a question for me too, if the user has chosen the wrong branch and opens PR. How can he correct it? Please add the necessary explanations to file workflow if possible.

datamweb avatar Aug 03 '22 05:08 datamweb

@datamweb If you have the PR branch feat-abc:

  1. Create a new branch feat-abc-new from the correct branch, and cherry-pick the commits you did.
  2. Delete the PR branch feat-abc, and rename the new branch feat-abc-new to feat-abc.
  3. Force push.
  4. On GitHub PR page, change the base branch to the correct branch.

kenjis avatar Aug 03 '22 07:08 kenjis

Great, got it. Thanks.

datamweb avatar Aug 03 '22 07:08 datamweb

@datamweb I sent a PR #6372

kenjis avatar Aug 12 '22 23:08 kenjis

@kenjis fixed to point toward 4.3 now

lonnieezell avatar Aug 21 '22 04:08 lonnieezell

Please add changelog and link to the details page: https://github.com/codeigniter4/CodeIgniter4/blob/4.3/user_guide_src/source/changelogs/v4.3.0.rst#enhancements

kenjis avatar Aug 21 '22 08:08 kenjis

What if this code is implemented as a trait? It does not depend on the query builder, so it can also be used, for example, on the Response class or model.

iRedds avatar Aug 25 '22 05:08 iRedds

Well, looks like pulling in the changes from remote screwed me over here. Will fix that tomorrow.

lonnieezell avatar Sep 06 '22 04:09 lonnieezell

I was sure I left a comment on this PR, but for some reason I didn't find it. I must have gotten too old. =)

I would like to suggest reconsidering the idea of this feature.

The when method is not logically related to databases and can be applied to the framework API. It seems to me that it would be more convenient to put this method into a separate trait, which can be added to such classes as Request, Response, Model, and other classes.

In addition to the when method, you can also add the whenNot method.

iRedds avatar Sep 15 '22 05:09 iRedds

The when method is not logically related to databases and can be applied to the framework API. It seems to me that it would be more convenient to put this method into a separate trait, which can be added to such classes as Request, Response, Model, and other classes.

In addition to the when method, you can also add the whenNot method.

@iRedds I think that's a great idea. Will do.

lonnieezell avatar Sep 23 '22 03:09 lonnieezell

Closing this as it's been replaced by #6574

lonnieezell avatar Sep 23 '22 04:09 lonnieezell