我无法在深层嵌套的关联中使用where
。
我在很多方面都尝试过,但在每次使用where
的情况下都不会采取行动
实际上,我的情况就像在文档中一样 https://book.cakephp.org/3.0/en/orm/query-builder.html#using-innerjoinwith
到目前为止我一直在尝试
$query = $itemTable
->find('all')
->contain(
[
'Products',
'ItemGroups',
'ItemGroups.FeaturesItemGroups.Features',
'Products.ProductCategories.ProductFractions',
'Products.ProductVessels',
'ItemCancellationReasons',
'Features',
'Users',
'Users.Groups',
'Orders',
'ItemPrices.ItemPricesBillingDocuments.RecyclerPrices.ProductFractions' => [
'conditions' => [
'ItemPricesBillingDocuments.id IS NOT NULL',
'ItemPricesBillingDocuments.billing_document_id' => $billingDocumentToRevert->id,
'ItemPricesBillingDocuments.billing_document_type_id' => BillingDocumentTypes::CREDIT_INDEX,
'ItemPricesBillingDocuments.active' => 1
]
]
]
);
第二个例子
->innerJoinWith(
'ItemPrices.ItemPricesBillingDocuments',
function ($q) use ($billingDocumentToRevert) {
return $q->where(
[
'ItemPricesBillingDocuments.id IS NOT NULL',
'ItemPricesBillingDocuments.billing_document_id' => $billingDocumentToRevert->id,
'ItemPricesBillingDocuments.billing_document_type_id' => BillingDocumentTypes::CREDIT_INDEX,
'ItemPricesBillingDocuments.active' => 1
]
)
->contain(['RecyclerPrices.ProductFractions']);
}
)
3
$query->where([
'ItemPricesBillingDocuments.id IS NOT NULL',
'ItemPricesBillingDocuments.billing_document_id' => $billingDocumentToRevert->id,
'ItemPricesBillingDocuments.billing_document_type_id' => BillingDocumentTypes::CREDIT_INDEX,
'ItemPricesBillingDocuments.active !=' => false
]);
在我的调试中,我得到active
标志为false
的结果。
Items表中的每个关系都是1:many
ItemsPrices.ItemPricesBillingDocuments也是1:many