Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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具有并属于许多不存在的条件_Mysql_Sql_Cakephp - Fatal编程技术网

Mysql CakePHP具有并属于许多不存在的条件

Mysql CakePHP具有并属于许多不存在的条件,mysql,sql,cakephp,Mysql,Sql,Cakephp,我正在尝试设置NOT EXISTS条件,如以下SQL语句: $conditions = Array ( [table] => products_pages [alias] => ProductsPage [type] => inner [foreignKey] => [conditions] => Array ( [0] => ProductsPage.product_id = Product.id ) ) 因此,基本上选

我正在尝试设置NOT EXISTS条件,如以下SQL语句:

$conditions = Array
(
  [table] => products_pages
  [alias] => ProductsPage
  [type] => inner
  [foreignKey] => 
  [conditions] => Array
  (
   [0] => ProductsPage.product_id = Product.id
  )
)
因此,基本上选择products_pages表中不存在的任何产品

为CakePHP格式化SQL语句并在此处替换它的正确方法是什么:

[条件]=>阵列 ( [0]=>(在此处插入以上SQL的正确方式是什么? )


非常感谢你们的帮助,我已经花了大约5个小时试图解决这个问题,但运气不好。谢谢!

如果您找不到使用CakePHP的方法,您可以随时使用
query

在这种情况下,安全性不会受到影响,因为您没有使用任何输入

不管怎样,简单的做法是只需一步多做:

SELECT * FROM products_pages,products 
WHERE NOT EXISTS (SELECT id 
                  from products_pages 
                  where products_pages.product_id = products.id)

如果你认为答案是有效的,那就太好了:)(我答案左边的勾号)
//selecting the products in the productcs_pages table
$productsWithPages = /* query to get them*/

//getting an array of IDs
$productsWidthPagesIds = Hash::extract($productsWithPages, '{n}.Product.id');

//doing the NOT IN to select products without pages
$productsWithoutPages= $this->Product->find('all', 
        array('conditions' => 
             array( 'NOT' => array('Product.id' => $productsWidthPagesIds )
        )
);