开发者

Trying to make models in Kohana, relations problem

I have a table of Hits, Articles and Categories

Now, a Hit belongs_to an Article/Category (depends on where it was done).

so I have a column on Hits table with the name 'parenttype'

That tells me 'Article' or 'Category'.

I wrote in the Hit model (extends ORM)

protected $_belongs_to= array(
    'page' => array('model'=> $this开发者_JAVA技巧->parenttype)
    );

Now it complains about $this->parenttype not being expected?


you should declare the variable protected $_belongs_to = NULL;

and on the constructor set it's value after calling the parent class constructor

public function __construct() {
    parent::__construct();
    $this->_belongs_to = array('page' => array('model' => $this->parenttype));
}


How do you intend to access $this if the object is just about to be instantiated? ( even if you could, $this->parenttype definitely hasn't been loaded before relations were )

This means you need to define that relation some other way, a little bit later :) ( I still don't like the way you're doing it )

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜