I have a page table. Pages can have parents, which are also pages. I want to select all pages with parent_id = NULL and their 'children'. But when I try this
public function getPages()
{
return $this->hasMany(Page::className(), ['parent_id' => 'id']);
}
I get a get a 1066 Not unique table/alias: 'page' error ... I know how to fix this in Yii1, but I can't figure out to fix it in Yii2.
You need to alias the table name.
See discussion here.