Reputation: 319
I have relations in main model
public function getItems(){
return $this->hasOne(OrderItems::className(), ['order_id' => 'order_id']);
}
In Items order_id
has many order_items_id
. How could I get all order_items_id
for order_id
in one cell in column?
Upvotes: 2
Views: 530
Reputation: 3008
The relation should be with hasMany
and not hasOne
public function getItems(){
return $this->hasOne(OrderItems::className(), ['order_id' => 'order_id']);
}
To solve your problem I'll try with raw sql, using GROUP_CONCAT:
$sql = "SELECT GROUP_CONCAT(order_items_id SEPARATOR ', ') FROM OrderItems";
$orderItemsIds = Yii::$app->db->createCommand($sql)->queryColumn();
Upvotes: 1