我有一个具有许多 SupplierInquiryProducts 的模型 SupplierInquiry 并且在 SupplierInquiryProducts 表中我有 product_id 外键并且 product_id 可以来自多个模型。我在 SupplierInquiryProducts 中应用了如下关系
$this->belongsTo('ConsumablesMaster', [
'foreignKey' => 'product_id',
'className' => 'ConsumablesMaster'
])->setConditions(['SupplierInquiry.inquiry_type'=>'Consumable']);
$this->belongsTo('ProductsMaster', [
'foreignKey' => 'product_id',
'className' => 'ProductsMaster'
])->setConditions(['SupplierInquiry.inquiry_type'=>'Chemical Product']);
public function buildRules(RulesChecker $rules){
$rules->add($rules->existsIn(['supplier_inquiry_id'], 'SupplierInquiry'));
$rules->add($rules->existsIn(['product_id'], 'ConsumablesMaster'));
$rules->add($rules->existsIn(['product_id'], 'ProductsMaster'));
return $rules;
}
在这里,belongTo 都不起作用,而且对于应用条件,它给出的错误是 Column not found: 1054 Unknown column 'SupplierInquiry.inquiry_type' in 'on Clause'