开发者

cakePHP: Why are my model associations not working as a plugin?

I have a relationship as follows.

  1. Game -> hasMany Highscores
  2. Highscore -> belongsTo Games, Users

When I run the MVC files standalone (within their respective places in the app dir), I get all belongsTo data associated with Highscores. However, when I run the same MVC files as a plugin, within the plugin dir, these associations are lost.

It seems to me that eve开发者_运维技巧rythig is in order, but to no avail. I am fairly new to cakePHP so I'm sure it's something stupid. I can't for the life figure it out however.

Any help would be greatly appreciated.

I have referenced:

book.cakephp.org/view/117/Plugin-Models trac.cakephp.org/ticket/3876 aranworld.com/article/143/cakephp-model-associations-from-within-plugin-directories


Are you setting up your relationships using the PluginName as the prefix in the joined Model's name?

That sounds awkward - example

<?php
    class MyModel extends AppModel
    {
        public $name = "MyModel";
        public $belongsTo = array(
            'User' => array(
                'className' => 'SparkPlug.User',
            ),
        );
?>


I ended up using the bindModel method.

$this->Highscore->bindModel(
    array('belongsTo' => array(
            'User' => array(
                'className' => 'SparkPlug.User'
            )
        )
    )
);

Not ideal and still unsure why my relationships/associations are getting lost. But this will have to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜