[PHP] Kohana-v3 ORM parent relationship
- by VDVLeon
Hi all,
I just started with the version 3 of the Kohana Framework.
I have worked a little with the $_has_many etc.
Now I have the table pages. The primary key is pageID. The table has a column called parentPageID. Now I want to make a ORM model who, when accesed like this $page->parent->find() returns the page identified by parentPageID.
I have the following already:
// Settings
protected $_table_name = 'pages';
protected $_primary_key = 'pageID';
protected $_has_one = array(
'parent' => array(
'model' => 'page',
'foreign_key' => 'parentPageID',
),
);
But that does not work, it simply returns the first page from the table. Last query says this:
SELECT `pages`.* FROM `pages` ORDER BY `pages`.`pageID` ASC LIMIT 1
Does somebody know how to solve this?
I know this can: $parent = $page->parent->find($page->parentPageID); but it must be and can be cleaner (I think).