Binding through variable declaration in model class doesn't work, but calling a bind function does work

十年热恋 提交于 2020-01-06 08:31:01

问题


I have the following model

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'

                    )
                )
            )
        ); 
    }

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?


回答1:


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.



来源:https://stackoverflow.com/questions/2828930/binding-through-variable-declaration-in-model-class-doesnt-work-but-calling-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!