是否可以在 cakephp 模型中与某些特定条件建立关系: 例如:
var $belongsTo = array(
'Parent' => array(
'className' => 'Category',
'foreignKey' => 'parent_id',
'dependent' => true
)
);
我想要上述关系,其中字段 parent_id
不为 0
。请概述一下如何做到这一点?
最佳答案
您可以在关系中添加条件,就像对查找结果所做的那样。
var $belongsTo = array(
'Parent' => array(
'className' => 'Category',
'foreignKey' => 'parent_id',
'dependent' => true,
'conditions' => array(
...
)
)
);
关于mysql - 带条件的 Cakephp 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13861081/