mysql - 如何在没有连接的情况下使用自关联条件?

标签 mysql cakephp associations cakephp-2.0

我有 Product 模型 [id, parent_id, x]。 我想在每个产品上附加单个 ProductParent,仅当 Product.x = 0Product.parent_id = ProductParent.id 时。

我尝试的是:

public $hasOne = array(
    'ProductParent' => array(
        'className' => 'Product',
        'foreignKey' => false,
        'conditions' => array(
            'ProductParent.id = Product.parent_id',
            'Product.x' => 0
        )
    )
);

并得到输出 Product.parent_id is unknown.

最佳答案

您可以尝试使用树行为。检查这个:http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html

关于mysql - 如何在没有连接的情况下使用自关联条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33256631/

相关文章:

mysql - Apache Superset 通过 Spark 连接到 Mariadb

php - 我想知道为什么不会生成 $Articles

ruby-on-rails - 当 :allow_destroy => true 时删除关联而不是销毁对象

CakePHP 3.x : all routes to the plugin

java - 此 UML 关联是否正确匹配代码?

ruby-on-rails - Rails 复选框不起作用 - 提交表单时没有错误

mysql - Symfony 中带有 ORDER BY 匹配条件的自定义 SQL 查询

php - 无法使用 pdo 导出到 csv

php - 使用 PHP OR/AND

cakephp - 用于 cakePHP 应用程序的 Redis