Laravel:在嵌套关系查询中获取根类

时间:2019-07-16 22:41:55

标签: laravel eloquent

如何使根类处于嵌套的渴望关系中?基本上,我想得到这样的东西:

        $entities = Entity::with(['attribute.valueable' => function ($query) {
            $root = $query->getRootParent();
            $query->where('entity_id', $root->id);
        }])->get();

SQL查询应该像

select * from `entities`;

select * from `entity_types_attributes` where `entity_types_attributes`.`entity_type_id` in (?);

select * from `entity_attribute_value_int` where `entity_attribute_value_int`.`attribute_id` in (?, ?, ?) 
AND `entity_attribute_value_int`.entity_id` = ? // this part should be appended

0 个答案:

没有答案