我有 Product
模型 [id, parent_id, x
]。
我想在每个产品上附加单个 ProductParent
,仅当 Product.x = 0
和 Product.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.
最佳答案
关于mysql - 如何在没有连接的情况下使用自关联条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33256631/