L
L
LittleFatNinja2016-10-26 14:44:22
Yii
LittleFatNinja, 2016-10-26 14:44:22

Yii2 active record. how to correctly compose a search with the with relation?

expression Menu::find()->with('page')
generates a query without attaching page i.e. fields are selectable only from the relay menu in the menu indicated
SELECT * FROM `menu`

public function getPage()
    {
        return $this->hasOne(Page::className(), ['id' => 'page_id']);
    }

Menu::find()->joinWith('page')
SELECT `menu`.* FROM `menu` LEFT JOIN `page`

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-26
@LittleFatNinja

It's not entirely clear what the problem is. I think you need joinWith

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question