ActiveRecord cascading models


I want to get some relations with their relations. We have some pages related to some categories. Each category is moderated by a user. I want to get from a single query all pages with their categories and the user

Let’s say we have 3 models:

class Page extends \yii\db\ActiveRecord {

    public function getCategory() {

        return $this->hasOne(PageCategory::className(), ['id_page_category' => 'id_category']);



class PageCategory extends \yii\db\ActiveRecord {

    public function getModerator() {

        return $this->hasOne(Moderator::className(), ['id_page_category' => 'id_category']);



class Moderator extends \yii\db\ActiveRecord {


I tried Page::find()->with(‘category’)->with(‘moderator’) and it didn’t worked.

How I can get relations with other relations?

Thank you


Page::find()->with('category')->with('category.moderator') ...

// or

Page::find()->with(['category', 'category.moderator']) ...

thanks. it worked.