I'm working on CakePHP 3.2.
I have categories
, products
, seller_products
table and their association are
categories->hasMany('Products');
seller_products->hasMany('Products');
I have to retrieve all products group by category where seller_products.stock > 0
This is what I'm doing
$pros1 = $this->Products->Categories->find()
->where([
'Categories.status' => 0,
])
->contain([
'Products.SellerProducts', 'Subcategories', 'Subcategories.ProductTypes'
])
->matching('Products.SellerProducts', function(\Cake\ORM\Query $q) {
return $q->where(['SellerProducts.stock >' => 0]);
});
but on debugging, it is returning same values twice.
foreach($pros1 as $p){debug($p);}
is printing same values twice
/src/Controller/PagesController.php (line 120)
object(App\Model\Entity\Category) {
'id' => (int) 1,
'title' => 'Electronics',
'description' => '',
'icon' => 'fa-television',
'status' => (int) 0,
'created' => object(Cake\I18n\Time) {
.........
}
/src/Controller/PagesController.php (line 120)
object(App\Model\Entity\Category) {
'id' => (int) 1,
'title' => 'Electronics',
'description' => '',
'icon' => 'fa-television',
'status' => (int) 0,
'created' => object(Cake\I18n\Time) {
.........
}
and debug(count($pros1))
prints 1