如果cakephp 3中包含为空,则删除父数组

时间:2018-10-30 04:59:50

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.2

如果contains不可用或为空,我必须删除父数组。在下面的代码中,如果SupplierOffer为空,那么我必须删除SupplierInquiry数组,但在这里,我得到的SupplierInquiry数组为空的SupplierOffer。我无法通过使用foreach循环来取消设置,因为这样计数将显示错误。 这个问题有解决方案吗?

    $this->paginate =   [
        'contain'=>['SupplierOffer'=>function($q){
            return $q->where(['SupplierOffer.status IS NULL']);
        },'CompanyMaster','SupplierOffer.PurchaseOrder','SupplierOffer.SupplierOfferProducts','SupplierOffer.SupplierOfferProducts.ProductsMaster','SupplierOffer.SupplierOfferProducts.Uom','SupplierOffer.SupplierOfferProducts.Currency', 'OwnerCompanies','SupplierOffer.CompanyMaster','SupplierOffer.SupplierOfferProducts.PrSuppliers'],
            'order'=>['SupplierInquiry.id' => 'DESC'],
            'conditions'=>[$condn,$conditions,'SupplierOffer IS NOT NULL'],
    ];
    $supplierOffer = $this->paginate($this->SupplierInquiry);

1 个答案:

答案 0 :(得分:1)

您需要使用内部联接并在子表上添加条件。  而且,您还需要指定要获取的字段。

$query = $this->SupplierInquiry->find()->where(['SupplierOffer.status IS NOT' => NULL])->hydrate(false)->join([
    'table' => 'supplier_offer',
    'alias' => 'SupplierOffer',
    'type' => 'INNER',
    'conditions' => 'SupplierOffer.supplier_inquiry_id = SupplierInquiry.id'
])->select(' All fields you required ');
相关问题