如何使根类处于嵌套的渴望关系中?基本上,我想得到这样的东西:
$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