|
6 | 6 | use ArrayObject; |
7 | 7 | use Cake\Core\Configure; |
8 | 8 | use Cake\Core\Exception\CakeException; |
9 | | -use Cake\Database\Expression\BetweenExpression; |
10 | | -use Cake\Database\Expression\ComparisonExpression; |
| 9 | +use Cake\Database\Expression\FieldInterface; |
11 | 10 | use Cake\Database\Expression\IdentifierExpression; |
12 | 11 | use Cake\Database\Query\SelectQuery; |
13 | 12 | use Cake\Datasource\EntityInterface; |
@@ -181,41 +180,39 @@ public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObjec |
181 | 180 | return; |
182 | 181 | } |
183 | 182 |
|
184 | | - $field = $this->getTrashField(); |
185 | | - |
186 | | - if ($this->shouldAddTrashCondition($query, $field)) { |
187 | | - $query->andWhere([$field . ' IS' => null]); |
| 183 | + if ($this->shouldAddTrashCondition($query)) { |
| 184 | + $query->andWhere([$this->getTrashField() . ' IS' => null]); |
188 | 185 | } |
189 | 186 | } |
190 | 187 |
|
191 | 188 | /** |
192 | 189 | * Whether we need to add the trash condition to the query |
193 | 190 | * |
194 | 191 | * @param \Cake\ORM\Query\SelectQuery $query Query. |
195 | | - * @param string $field Trash field |
196 | 192 | * @return bool |
197 | 193 | */ |
198 | | - protected function shouldAddTrashCondition(SelectQuery $query, string $field): bool |
| 194 | + protected function shouldAddTrashCondition(SelectQuery $query): bool |
199 | 195 | { |
| 196 | + $fieldIdentifiers = [$this->getTrashField(false), $this->getTrashField()]; |
200 | 197 | $addCondition = true; |
201 | 198 |
|
202 | | - $query->traverseExpressions(function ($expression) use (&$addCondition, $field): void { |
| 199 | + $query->traverseExpressions(function ($expression) use (&$addCondition, $fieldIdentifiers): void { |
203 | 200 | if (!$addCondition) { |
204 | 201 | return; |
205 | 202 | } |
206 | 203 |
|
207 | 204 | if ( |
208 | 205 | $expression instanceof IdentifierExpression |
209 | | - && $expression->getIdentifier() === $field |
| 206 | + && in_array($expression->getIdentifier(), $fieldIdentifiers, true) |
210 | 207 | ) { |
211 | 208 | $addCondition = false; |
212 | 209 |
|
213 | 210 | return; |
214 | 211 | } |
215 | 212 |
|
216 | 213 | if ( |
217 | | - ($expression instanceof ComparisonExpression || $expression instanceof BetweenExpression) |
218 | | - && $expression->getField() === $field |
| 214 | + $expression instanceof FieldInterface |
| 215 | + && in_array($expression->getField(), $fieldIdentifiers, true) |
219 | 216 | ) { |
220 | 217 | $addCondition = false; |
221 | 218 | } |
|
0 commit comments