You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,22 +228,24 @@ Customer::find()->with('orders.oops')->all(); // ✗ typo — no such rela
228
228
229
229
#### Active Record condition validation
230
230
231
-
`findOne()`, `findAll()`, and `deleteAll()` take a plain array condition (`['attribute' => value]`, with an array value matched as an `IN (...)` condition) — and so does the second, condition argument of `updateAll()` / `updateAllCounters()`. Like `attributeLabels()` and `scenarios()`, this is never checked against the model until the query actually runs. This rule checks that every attribute name in a condition array exists on the queried ActiveRecord model (the same `@property`-aware resolution as `activeRecordRelationValidation`) and that its value's type is compatible with the attribute's declared type. Only array literals with a resolvable string key are checked; primary-key-only lookups (`findOne(1)`, `findOne([1, 2])`) and dynamically-built condition arrays are left alone.
231
+
`findOne()`, `findAll()`, and `deleteAll()` take a plain array condition (`['attribute' => value]`, with an array value matched as an `IN (...)` condition) — and so does the second, condition argument of `updateAll()` / `updateAllCounters()`. Like `attributeLabels()` and `scenarios()`, this is never checked against the model until the query actually runs. This rule checks that every attribute name in a condition array exists on the queried ActiveRecord model (the same `@property`-aware resolution as `activeRecordRelationValidation`) and that its value's type is compatible with the attribute's declared type. Only array literals with a resolvable string key are checked; primary-key-only lookups (`findOne(1)`, `findOne([1, 2])`) and dynamically-built condition arrays are left alone. A value implementing `yii\db\ExpressionInterface` (e.g. `new Expression('NOW()')`) is accepted for any attribute regardless of its declared type — `yii\db\conditions\HashConditionBuilder` builds it as raw SQL instead of type-casting it, and does so per-value inside an `IN (...)` array too.
232
232
233
233
```php
234
234
/**
235
235
* @property int $id
236
236
* @property int $status
237
+
* @property string $updated_at
237
238
*/
238
239
final class Customer extends ActiveRecord { /* ... */ }
239
240
240
-
Customer::findOne(1); // ✓ primary key lookup, not a condition hash
241
-
Customer::findOne(['status' => 1]); // ✓
242
-
Customer::findOne(['status' => [1, 2]]); // ✓ IN (1, 2)
Customer::updateAll(['status' => 1], ['idd' => 5]); // ✗ typo — unknown attribute in the condition
247
249
```
248
250
249
251
#### Active Record relations validation
@@ -296,21 +298,23 @@ final class OrderItem extends ActiveRecord { /* ... */ }
296
298
297
299
#### Active Record update values validation
298
300
299
-
`updateAll()`'s attribute values and `updateAllCounters()`'s counter values are the other plain array these two methods take — the values written into the row, as opposed to the WHERE condition `activeRecordConditionValidation` checks. This rule checks that every attribute name exists on the ActiveRecord model and that its value's type is compatible with the attribute's declared type; unlike a condition, these values are written as-is, so (unlike `activeRecordConditionValidation`) an array value is not treated as an `IN (...)` shorthand and is always a type mismatch.
301
+
`updateAll()`'s attribute values and `updateAllCounters()`'s counter values are the other plain array these two methods take — the values written into the row, as opposed to the WHERE condition `activeRecordConditionValidation` checks. This rule checks that every attribute name exists on the ActiveRecord model and that its value's type is compatible with the attribute's declared type; unlike a condition, these values are written as-is, so (unlike `activeRecordConditionValidation`) an array value is not treated as an `IN (...)` shorthand and is always a type mismatch. As with a condition, a value implementing `yii\db\ExpressionInterface` is accepted for any attribute regardless of its declared type — `yii\db\QueryBuilder::prepareUpdateSets()` builds it as raw SQL instead of type-casting it.
300
302
301
303
```php
302
304
/**
303
305
* @property int $id
304
306
* @property int $status
305
307
* @property int $age
308
+
* @property string $updated_at
306
309
*/
307
310
final class Customer extends ActiveRecord { /* ... */ }
0 commit comments