Answer the question
In order to leave comments, you need to log in
How to find all ancestors without grandchildren?
I know that the wording of the question sounds strange, but I couldn't help it.
there is something like this query that looks for all elders, parents and childs.
SELECT `elders`.* FROM `elders` LEFT JOIN `parents` ON `elders`.`col` = `parents`.`elders_col` LEFT JOIN `childs` ON `parents`.`col` = `childs`.`parents_col`
$model = Elders::find()->joinWith('parents.childs')->asArray()->all();
Answer the question
In order to leave comments, you need to log in
you just need to add to the current query WHERE `childs`.`parents_col` IS NULL
looks like this (sql):
yii2:
Elders::find()->joinWith('parents.childs')->where(['childs.parents_col' => null])->asArray()->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question