Add extendWhere, orWhere and andWhere methods to database query class.#5837
Add extendWhere, orWhere and andWhere methods to database query class.#5837chrisdavenport wants to merge 3 commits intojoomla:stagingfrom chrisdavenport:db-where
Conversation
|
awesome, i waiting this 😄 |
|
I've tested this and it works. With the new syntax one has to be really careful in what order the andWhere and orWhere parameters are added. If you change their position something completely different than expected would come out. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5837. |
|
Given an arbitrary query object with some unknown WHERE clause, adding an andWhere or an orWhere to it would, I think, give exactly the result you would expect. If you were to add a where([something], 'and') or a where([something], 'or') you would very likely get something unexpected since the second argument would be ignored, so I would say that the behaviour of the existing methods is rather more unexpected. Can you give me an example of something unexpected coming out when using andWhere or orWhere? |
|
💯 Would be nice to see this maybe added to 3.5 |
|
Then please test it and report your findings. Without testers it cannot be committed. ;-) |
|
I attempted to test the patch but I get an error. I'm guessing that this error is due to "This branch has conflicts that must be resolved" or some other issue with the patch tester. |
|
Nope, it's right. It looks like the source branch for this pull request was deleted. |
|
Git got its knickers in a twist a while back and the only solution was to delete my repo and start again with a clean fork. I'll create a new PR. |
|
Closing in favour of #8718 |
The current implementation of the database query where method is limited by an unfortunate restriction in that the first use of the glue parameter fixes the glue for all subsequent uses. For example,
This behaviour is inconvenient but can't be changed in Joomla 3.x because it would break backwards compatibility. Consequently, this PR offers the following additional syntax to support more complex WHERE clauses:
orWhere($conditions, $glue = 'AND')
andWhere($conditions, $glue = 'OR')
extendWhere($outerGlue, $conditions, $innerGlue = 'AND')
The extendWhere method allows additional logical operators to be used beyond the commonly used AND and OR operators. For example, you can use XOR, AND NOT and OR NOT.
Backwards compatibility
There are no backwards compatibility issues. Existing code is unaffected because only new syntax is being added.
Testing
The code is accompanied by unit tests for the new methods and an extension to the where method test which verifies the original behaviour.