делаю вот так
Код: Выделить всё
return Book::find()
->with('chapters')
->where(['>= ', 'book.id', 1])
->andWhere(['<=', 'book.id', 2])
->all();
Код: Выделить всё
public function getChapters($short = false)
{
return $this->hasMany($short ? ChapterShort::className() : Chapter::className(), ['bookId' => 'id'])
->limit(5);
}