Answer the question
In order to leave comments, you need to log in
How to write and where is left join?
I need to make sure that in yii2 the id is not displayed, but the name of the employee. sql code i know what it looks like
SELECT * FROM `zakaz` LEFT JOIN otdel ON zakaz.id_sotrud=otdel.id
$customers = Customer::find()
->select('customer.*')
->leftJoin('order', '`order`.`customer_id` = `customer`.`id`')
->where(['order.status' => Order::STATUS_ACTIVE])
->with('orders')
->all();
class ZakazQuery extends \yii\db\ActiveQuery
{
$zakaz = Zakaz::find()
->select('zakaz.*')
->leftJoin('otdel', '`zakaz`.`id_sotrud` = `otdel`.`id`')
->all();
Answer the question
In order to leave comments, you need to log in
Good evening.
Is all employee data in one table stored or in different ones?
If in different, then you can do without left join, use links between tables instead.
More details here (working with connected data)
class Zakaz extends ActiveRecord
{
public function getOtdel()
{
return $this->hasOne(Otdel::className(), ['id_sotrud' => 'id']);
}
}
class Otdel extends ActiveRecord
{
public function getOrders()
{
return $this->hasMany(Zakaz::className(), ['id' => 'id_sotrud']);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question