Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp—按包含的模型中的字段排序_Php_Cakephp - Fatal编程技术网

cakephp—按包含的模型中的字段排序

cakephp—按包含的模型中的字段排序,php,cakephp,Php,Cakephp,我正在尝试获取特定类别中的所有产品(产品有许多类别)。我的条件是Category.name='whatever'和Product.live=1 我可以这样做: $cats = $this->Category->find('all', array( 'conditions' => array( 'Category.name' => $categoryName ), 'contain' => 'Product.live = 1'

我正在尝试获取特定类别中的所有产品(产品有许多类别)。我的条件是Category.name='whatever'和Product.live=1

我可以这样做:

$cats = $this->Category->find('all', array(
    'conditions' => array(
        'Category.name' => $categoryName
    ),
    'contain' => 'Product.live = 1'
));
但我也想按Product.sort\u顺序对结果进行排序,因此我尝试:

$cats = $this->Category->find('all', array(
    'conditions' => array(
        'Category.name' => $categoryName
    ),
    'order' => array('Product.sort_order'),
    'contain' => 'Product.live = 1'
));

但这不起作用。正确的方法是什么?

TLDR:使用联接而不是包含(或交换查找方向)


我有溢出-不确定是否只是没有出现在…等等,但是-您不能按包含的模型订购,因为包含通常会创建多个/单独的查询。

OMG@scrowler-您找到并链接了所有查询。我希望我能为那件事+1你。让我笑了。