我在两个实体/表之间有一对多的关系。
/**
* Get all of the products.
*/
public function products()
{
return $this->belongsToMany(Product::class)->select(
[
'products.id',
'products.title',
'products.sku',
'automation_products.automation_id as auto_id',
'display_order',
]
)->orderBy('display_order');
}
当我想急切加载这种关系时,似乎有重复的查询在后台运行。我使用此代码急切加载我的关系:
$automation = \App\Models\Automation::with('products')->whereId(1)->get()->first();
dump($automation->products()->get());
dump($automation->products()->get());
dump($automation->products()->get());
有什么我想念的吗?
谢谢回复。