ads
ads

Reputation: 3

How to use left join yii2

I have this code in yii 1

$criteria->join = 'left join item_attr_val v ON i.item_id=t.id';
$values = array();
                    foreach ($feature as $key => $value) {
                        if ($value == '1')
                            $values [] = $key;
                    }
$criteria->compare('i.attr_value_id', $values);

how can I use in yii2

Upvotes: 0

Views: 407

Answers (2)

vishuB
vishuB

Reputation: 4261

You Try this One...

$query = Model::find();
$query->join('LEFT JOIN', 'item_attr_val', "item_id = id");

Upvotes: 1

GAMITG
GAMITG

Reputation: 3818

You can use leftjoin.

e.g

$query = ModelName::find();
$query->leftJoin('item_attr_val', "tableName.item_id = tableName2.id");

Upvotes: 1

Related Questions