$slider = Slider::find()
->joinWith([
'slides' => function (ActiveQuery $query) {
$query->addOrderBy(sprintf('%s.position', Slide::tableName()));
}
], false)
->one();
/* OK */
SELECT "sliders".*
FROM "sliders"
LEFT JOIN "slider_slides"
ON "sliders"."id" = "slider_slides"."slider_id"
ORDER BY "slider_slides"."position"
问题是,当我加入关系$slider->slides
时,调试器会向我显示其他查询:
SELECT * FROM "slider_slides" WHERE "slider_id"=1
加入无用的。