views:

46

answers:

1

Hi all, I have recently started to use Kohana and I know inheritance is in infancy stages at the moment. The work around is using a $_has_one annotation on the child class model. In may case i have "page" as the parent of "article". I have something like,

protected $_has_one = array('mypage'=>array('model'=>'page', 'foreign_key'=>'id'));

In my controller, I have an action which queries the database. In this query I am trying to access fields from the parent of "article" which is the "page".

    $n->articles=ORM::factory('article')->where('expires','=',0)
        ->where('articledate','<',date('y-m-d'))
        ->where('expirydate','>',date('y-m-d'))
        ->where('mypage->status','=','PUBLISHED')
        ->order_by('articledate','desc')
        ->find_all();

The status column resides in the page table and my query is generating an error to the effect of "cannot find status", clearly because it belongs to the parent.

Any ideas ?

+2  A: 

It may be possible to use with like this:

    $n->articles=ORM::factory('article')->with('mypage')
    ->where('expires','=',0)
    ->where('articledate','<',date('y-m-d'))
    ->where('expirydate','>',date('y-m-d'))
    ->where('status','=','PUBLISHED')

Which creates a join between two one to one tables.

Vincent Ramdhanie