D
D
des1roer2017-05-30 12:44:29
Yii
des1roer, 2017-05-30 12:44:29

Yii2 left join with condition?

need a request

select news.* from news left join
news_trademark on news_trademark.news_id = news.id
and news_trademark.trademark_id = 747
left join trademark on trademark.id = news_trademark.trademark_id
and trademark.photo is null
where  trademark.id is null

AR
public function getTrademarks()
    {
        return $this->hasMany(Trademark::class, ['id' => 'trademark_id'])->viaTable('news_trademark', ['news_id' => 'id']);
    }

How can i do this?
via News::find()->leftJoin() or News::find()->with()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dilik Pulatov, 2017-05-30
@dilikpulatov

something like that

public function getContent(){
    return $this->hasOne(PostContent::classname(),['post_id' => 'id'])
                ->select(['post_content.name','post_content.post_id','post_content.language'])
                ->where(['post_content.language'=>Yii::$app->params['admin_lang']]);
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question