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']);
    }

我想限制数据以查找大于 0 的stock位置。selling_price

但这不起作用。如何申请条件findById

4

1 回答 1

1

试试这个 :

$products = $this->paginate($this->Products->findByCategoryId($categoryId)->where(['stock >' => 0, 'selling_price >' => 0])->limit(21));

给出了 $categoryId。

于 2016-07-18T12:13:43.173 回答