CakePHP 3:大于 0 的 findById
CakePHP 3 : findById where greater than 0
我在另一个模型的 view()
函数中对关联模型进行分页。
public function view($id = null)
{
$category = $this->Categories->get($id, [
'contain' => ['Subcategories']
]);
// paginate products
$products = $this->paginate($this->Categories->Products->findByCategoryId($category->id, ['conditions' => ['stock >' => 0, 'selling_price >' => 0]]), [
'limit' => 21
]);
$this->set('products', $products);
$this->set('category', $category);
$this->set('_serialize', ['category']);
}
我想限制数据以查找 stock
和 selling_price
大于 0 的位置。
但这不起作用。如何在 findById
上应用条件?
试试这个:
$products = $this->paginate($this->Products->findByCategoryId($categoryId)->where(['stock >' => 0, 'selling_price >' => 0])->limit(21))
;
给定 $categoryId。
我在另一个模型的 view()
函数中对关联模型进行分页。
public function view($id = null)
{
$category = $this->Categories->get($id, [
'contain' => ['Subcategories']
]);
// paginate products
$products = $this->paginate($this->Categories->Products->findByCategoryId($category->id, ['conditions' => ['stock >' => 0, 'selling_price >' => 0]]), [
'limit' => 21
]);
$this->set('products', $products);
$this->set('category', $category);
$this->set('_serialize', ['category']);
}
我想限制数据以查找 stock
和 selling_price
大于 0 的位置。
但这不起作用。如何在 findById
上应用条件?
试试这个:
$products = $this->paginate($this->Products->findByCategoryId($categoryId)->where(['stock >' => 0, 'selling_price >' => 0])->limit(21))
;
给定 $categoryId。