Reputation: 8216
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->parenttype)
);
Now it complains about $this->parenttype not being expected?
Upvotes: 0
Views: 336
Reputation: 2376
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));
}
Upvotes: 1
Reputation: 7042
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 )
Upvotes: 0