私はCakePHP 3.2で作業しています。CakePHP:同じ値を2回印刷するクエリ
私はcategories
、products
、seller_products
テーブルとの関連付けが
categories->hasMany('Products');
seller_products->hasMany('Products');
ありきseller_products.stock> 0
は、これは私が
をやっているここで私は、カテゴリ別にすべての製品グループを取得する必要が$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]);
});
しかし、デバッグ時には同じ値を2回返します。 foreach($pros1 as $p){debug($p);}
が同じ値を二回
/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) {
.........
}
とdebug(count($pros1))
プリントドキュメントから1
ありがとうございました。マッチングは機能しません。それはまだ 'SellerProducts.stock = 0'で製品を表示しています –
@AnujTBEこれは別の質問です。それはマッチングの仕方ではありません。 Matchingフィルタは親レコードをフィルタリングします。子レコード( 'SellerProducts')が含まれていて、特定のレコードのみを必要とする場合は、それらもフィルタリングする必要があります。 ** http://stackoverflow.com/a/26800203/1392379**を参照してください。 – ndm