Problem/Motivation
Entity query has a use case for "disabling" a db query condition (i.e. a kill switch on the condition). The current implementation does not work if we decide to escape all identifiers/fields of a condition by default, as discussed in #2966523: MySQL 8 Support.
Contrib also has this use case, for example in the Tree module.
Proposed resolution
Add a alwaysFalse() method to \Drupal\Core\Database\Query\ConditionInterface and implement it in \Drupal\Core\Database\Query\QueryConditionTrait.
Remaining tasks
Review, etc.
User interface changes
Nope.
API changes
API addition, a new method on ConditionInterface.
Data model changes
Nope.
Comments
Comment #2
amateescu commentedThis should do it.
Comment #4
amateescu commentedThis should be better.
Comment #5
jibranComment #6
alexpottI think this can be
$this->condition->alwaysFalse()?Comment #7
amateescu commentedRight you are.
Comment #8
amateescu commentedHere's the test coverage needed. No test-only patch because it's a new feature.
Comment #9
jibranThis looks good to me. We do need a change record for this.
Comment #10
alexpottdb_select() is deprecated. Let's not add new usages - especially when
$this->connectionis available. Don't update the rest of the test though - thats not in scope.+1 to the change record.
Comment #11
daffie commentedShould we not add a deprecation notice with the condition method that
->condition('1 <> 1')will not longer work after the release of Drupal 9.0.Comment #12
amateescu commentedAdded a CR (https://www.drupal.org/node/2986827) with explicit wording about the incorrect usage of
->condition('1 <> 1')and fixed #10.Comment #13
alexpottOne thing to note is that
->condition('1 <> 1')only works by complete and utter accident!Checkout the output for
it's
And the value for
:db_condition_placeholder_0is an empty string. So by complete fluke it works.I think we should consider deprecating the ability to pass a string for
$fieldand NULL for$valueand$operatoris equal to=(its default value) in\Drupal\Core\Database\Query\ConditionInterface::condition(). The only time a NULL for $value makes sense is if$fieldis a\Drupal\Core\Database\Query\ConditionInterfaceor$operationis a unary operator.Comment #14
alexpottHere's probably the best way to deprecate this... let's see what falls out the trees.
Comment #15
amateescu commentedThat's an interesting proposal but I think it needs its own dedicated issue in order to be discussed properly. This one (including the CR) is just about adding the helper and make people aware to not shoot themselves in the foot :)
Comment #16
amateescu commentedRe-uploading #12 to be clear about which patch is ready for review/rtbc.
Comment #18
alexpottThe change record looks good. The new method is documented correctly and there is test coverage of nearly everything. The only thing missing coverage afaics is:
There is no test coverage of this. We should add some by repeating the test added and doing
->extend('Drupal\Core\Database\Query\SelectExtender')Comment #19
amateescu commentedVery good point, added test coverage for the extender as well.
Comment #20
alexpottThanks @amateescu - as per #18 - now everything is addressed.
Comment #21
bojanz commentedThis is a good idea. +1 for RTBC
I initially expected the method to be falsify(), so that it's a verb and not an adjective, but maybe that makes the method less obvious.
Comment #23
jibranComment #24
catchCommitted 8f1228f and pushed to 8.7.x. Thanks!