通过模型类中的变量声明绑定不起作用,但调用绑定函数不起作用 [英] Binding through variable declaration in model class doesn't work, but calling a bind function does work
问题描述
我有以下模型
class Comment extends AppModel {
var $useTable = "comments";
var $recursive = 1;
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'userID'
)
);
function bindCommentsToUser() {
$this->bindModel(
array('belongsTo' => array(
'User' => array(
'className' => 'User',
'foreignKey' => 'userID'
)
)
)
);
}
上面的belongsTo变量绝对没有什么,我只是无法得到它工作。
为了确认绑定存在,我创建了下面的功能来做动态绑定,完美地工作。两者似乎没有区别。
The belongsTo variable at the top does absolutely nothing, I just cannot get it to work. To confirm that the binding exists, I created the lower function to do dynamic binding which works perfectly. There appears to be no difference between the two. Is there some mistake that I am making or is there some setting somewhere else that has to be set?
推荐答案
应该有一个错误,在两种情况下相同。您可能需要在 http://cakephp.lighthouseapp.com 上创建故障单。如果可能,请将userID更改为user_id,如推荐的Travis Lleu。这将肯定工作。
There should be the same in both cases. You may want to create a ticket at http://cakephp.lighthouseapp.com. If possible change 'userID' to 'user_id' as recommended Travis Lleu. That will work for sure.
这篇关于通过模型类中的变量声明绑定不起作用,但调用绑定函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!