Answer the question
In order to leave comments, you need to log in
How to set SQL query in Yii2 via AD?
There is a request like
SELECT n.id, n.name, SUBSTRING(n.`text`, 1, 256 ) AS `text`, cat.id as cat_id, cat.name as cat_name
FROM news n
LEFT JOIN category as cat on (cat.id = n.category_id)
WHERE category_id = 1
$query = News::find()
->select([
'{{%news}}.`id`',
'{{%news}}.`name`',
'SUBSTRING({{%news}}.`text`, 1, 256 ) AS `text`',
'{{%news}}.`date`',
'{{%category}}.`id` AS cat_id',
'{{%category}}.`name` AS `cat_name`'
])
->leftJoin('{{%category}}', '{{%category}}.id = {{%news}}.category_id')
->where($where['where'], $where['arr']);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question