0

I have to remove the parent array if the contain is not available or empty. In below code if supplierOffer is empty then I have to remove the SupplierInquiry array but here I am getting the SupplierInquiry array with empty supplierOffer. I cann't unset by using foreach loop because then the count will show wrong. Any solution for this issue?

    $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);
Devendra
  • 219
  • 2
  • 22
  • 1
    I think that [matching](https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#filtering-by-associated-data-via-matching-and-joins) is what you need. – Greg Schmidt Oct 30 '18 at 13:32

1 Answers1

1

You need to use Inner join and pu the condition on child table. And also you need to specify fields you want to fetch.

$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 ');
Rakesh
  • 505
  • 5
  • 12