我有这个模特:
Proforma
->hasMany('ItemProformas', ['foreignKey' => 'proforma_id']);
->belongsTo('Customers', ['foreignKey' => 'customer_id']);
->belongsTo('ProformaStates', ['foreignKey' => 'proforma_state_id']);
->hasMany('Invoices', ['foreignKey' => 'proforma_id']);
ItemProformas
->belongsTo('Proformas', ['foreignKey' => 'proforma_id', 'joinType' => 'INNER']);
->belongsTo('ItemDeliveryNotes', ['foreignKey' => 'item_delivery_note_id']);
ItemDeliveryNotes
->belongsTo('DeliveryNotes', ['foreignKey' => 'delivery_note_id', 'joinType' => 'INNER']);
->belongsTo('ItemOrders', ['foreignKey' => 'item_order_id']);
->belongsTo('ItemOrdersTypes', ['foreignKey' => 'item_orders_type_id']);
->belongsTo('Products', ['foreignKey' => 'product_id']);
每个ItemProforma
可能带有一个ItemDeliveryNotes
,否则外键将为null
。这是我的paginate
电话:
$this->paginate = [
'contain' => [
'Customers',
'ProformaStates',
'ItemProformas' => ['ItemDeliveryNotes' => ['DeliveryNotes']]
]
];
使用此模型,我获得了have itemProforma
设置的所有item_delivery_note_id
。相反,即使item_delivery_note_id
为null
,我也很想获得所有这些信息。
我不确定belongsTo
是否正确(我的意思是ItemProformas
定义)。但是hasOne
表示它即使它们没有任何itemProformas
关联,检索all ItemDeliveryNote
的正确语法是什么?但是如果有,我也需要检索ItemDeliveryNote
对象。
我有这个模型:Proforma-> hasMany('ItemProformas',['foreignKey'=>'proforma_id'])); -> belongsTo('Customers',['foreignKey'=>'customer_id']); -> belongsTo('ProformaStates,[...