-
-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
type:featureNew featureNew feature
Description
Currently AR supports scalar to array relations:
$this->hasMany(Item::class, ['id' => 'item_ids'])
where id is integer column
and item_ids is integer array column
But AR does not support array to scalar relations
$this->hasMany(Promotion::class, ['item_ids' => 'id'])
The reason is in preparing the query condition. Currently it is only IN condition
active-record/src/ActiveRelationTrait.php
Line 636 in b000730
| $this->andWhere(['in', $attributes, $values]); |
Which will generate condition like id IN (1, 2, 3)
But for array column this should be arrays overlap condition like item_ids && ARRAY[1, 2, 3] (Postgres)
To solve the issue it requires:
- Realize
ArrayOverlapConditionandJsonOverlapCondition(for json arrays) in db packages - Add
AR::columnType($columnName)method to get type of the column - Prepare condition according to the column type:
match ($columnType) {
'array' => $this->andWhere(new ArrayOverlapCondition($attributes, $values)),
'json' => $this->andWhere(new JsonOverlapCondition($attributes, $values)),
default => $this->andWhere(['in', $attributes, $values]),
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type:featureNew featureNew feature