Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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
Mysql CakePHP通过isn查找组';在生成的查询中输入t_Mysql_Cakephp_Group By_Find_Cakephp 2.0 - Fatal编程技术网

Mysql CakePHP通过isn查找组';在生成的查询中输入t

Mysql CakePHP通过isn查找组';在生成的查询中输入t,mysql,cakephp,group-by,find,cakephp-2.0,Mysql,Cakephp,Group By,Find,Cakephp 2.0,我们有一个相当全面的发现,请参见下面的代码,按部分分组。由于某些原因,组部分不工作,甚至不在生成的查询中。正因为如此,我们在发现中得到了双重结果(为什么我们首先要使用GROUPBY函数) 如您所见,没有分组依据。我们还尝试在Product.id上使用DISTINCT,但这也不起作用。如果您自己运行查询并在组中运行部分,我们会得到想要的结果。我们还尝试将组部分放入一个数组中,如'GROUP'=>数组('Product.id'),但没有成功 那么,为什么我们的发现忽略了我们的组部分呢?我们怎样才能做

我们有一个相当全面的发现,请参见下面的代码,按部分分组。由于某些原因,组部分不工作,甚至不在生成的查询中。正因为如此,我们在发现中得到了双重结果(为什么我们首先要使用GROUPBY函数)

如您所见,没有
分组依据
。我们还尝试在
Product.id
上使用
DISTINCT
,但这也不起作用。如果您自己运行查询并在
组中运行
部分,我们会得到想要的结果。我们还尝试将
部分放入一个数组中,如
'GROUP'=>数组('Product.id')
,但没有成功


那么,为什么我们的发现忽略了我们的
部分呢?我们怎样才能做到不被忽视呢?

事实证明这是我们自己的错。我们团队中的某个人制作了一个自定义分页函数,它没有传递组变量。当时我没有意识到这一点。当我在另一个项目中使用他的函数时,我有一个“我现在就知道了”的时刻。

查看的代码示例,Group参数是作为数组提供的。我们已经尝试将其放入数组中,但没有成功。我应该在我的帖子里澄清一下,我会在里面编辑它。
$this->Product->Behaviors->load('Containable');
$this->paginate = array(
    'contain' => array(
        'Reduction' => array(
            'fields' => array(
                'Reduction.id', 'Reduction.startdate', 'Reduction.enddate', 'Reduction.price'
            ),
            'conditions' => array(
                'Reduction.startdate <' => date('Y-m-d H:00:00'),
                'Reduction.enddate >' => date('Y-m-d H:00:00'),
            ),
        ),
        'Mediafile',
        'Deliverytime' => array(
            'fields' => array(
                'Deliverytime.id', 'Deliverytime.name'
            )
        )
    ),
    'fields' => array(
        'Product.id', 'Product.name', 'Product.slug', 'Product.price', 'Product.content_short', 'Product.metadescription', 'Product.name_short',
        'Category.id', 'Category.name', 'Category.slug',
    ),
    'conditions' => array(
        'Product.status' => 'active',
        'Product.visibility' => 1,
        'Product.hidden_on_site' => 0,
        'OR' => array(
            array(
                'AND' => array(
                    array('Product.use_stock_count' => 0)
                )
            ),
            array(
                'AND' => array(
                    array('Product.use_stock_count' => 1),
                    array('Product.stock_count >=' => 1)
                )
            ),
        ),
    ),
    'joins' => array(
        array(
            'table' => 'products_categories',
            'alias' => 'ProductsCategory',
            'type' => 'INNER',
            'conditions' => array(
                'ProductsCategory.category_id' => $cat_ids,
                'ProductsCategory.product_id = Product.id',
            )
        ),
        array(
            'table' => 'categories',
            'alias' => 'Category',
            'type' => 'INNER',
            'conditions' => array(
                'Category.id = ProductsCategory.category_id',
            )
        ),
    ),
    'order' => 'Product.price ASC',
    'group' => 'Product.id',
    'limit' => $limit,
    'recursive' => -1,
    'page' => $page_number,
);
$products = $this->paginate('Product');
SELECT `Product`.`id`, `Product`.`name`, `Product`.`slug`, `Product`.`price`, `Product`.`content_short`, `Product`.`metadescription`, `Product`.`name_short`, `Category`.`id`, `Category`.`name`, `Category`.`slug`, `Deliverytime`.`id`, `Deliverytime`.`name`, `Product`.`id` 
FROM `products` AS `Product` 
LEFT JOIN `deliverytimes` AS `Deliverytime` ON (`Product`.`deliverytime_id` = `Deliverytime`.`id`) 
INNER JOIN `products_categories` AS `ProductsCategory` ON (`ProductsCategory`.`category_id` IN ('15', '306', '308', '309', '26', '167', '248', '185', '115', '116', '23', '258', '201', '22', '16', '17', '25', '19', '18', '114', '27', '127', '158', '136') AND `ProductsCategory`.`product_id` = `Product`.`id`) 
INNER JOIN `categories` AS `Category` ON (`Category`.`id` = `ProductsCategory`.`category_id`)  
WHERE `Product`.`status` = 'active' AND `Product`.`visibility` = '1' AND `Product`.`hidden_on_site` = '0' AND ((`Product`.`use_stock_count` = '0') OR (((`Product`.`use_stock_count` = '1') AND (`Product`.`stock_count` >= 1)))) 
ORDER BY `Product`.`price` ASC  
LIMIT 18