0
我有一些表:渴望負載嵌套的倍數關係
- 記錄
- record_relations
- 標識
- 庫存
- 價格
Record
具有多態性關係一起涉及Identification
,Inventory
和Price
。 Inventory
與Metric
和Price
有關係,與Currency
有關係。所以......
Record
hasMany
RecordRelations
通過relations()
RecordRelation
morphTo
Identification
,Inventory
和Price
通過relation()
Inventory
belongsTo
Metric
通過metric()
Price
belongsTo
Currency
通過currency()
如果我懶加載一切正常,但我需要加載所有關係(我將它們顯示在數據表中);嘗試了很多之後,我能夠加載最深的關係:如果我添加其他的關係我已經清空所有關係
$builder->with([
'relations' => function($query) {
$query->with('relation.metric')->where('relation_type', '=', 'App\\Inventory');
}
]);
但是......
$builder->with([
'relations' => function($query) {
$query->with('relation');
$query->with('relation.metric')->where('relation_type', '=', 'App\\Inventory');
$query->with('relation.currency')->where('relation_type', '=', 'App\\Price');
}
]);
看來我不能,某些原因,「withWhere
」不止一次。有沒有辦法做到這一點?
爲了訪問'關係'我需要通過'relations.relation',這樣工作嗎? – fred00
沒有它沒有必要...但如果關係表是從關係表中獲取引用,那麼它是必需的。 –