I'm building a credit card applicatoin around the Kohana framework. For content management, I'll be while using Joomla framework, so our copywriters can certainly add and edit content inside a for them familiar UI.

I've defined several groups that articles can fit in with. E.g. blog (catid = 1) and product (catid = 2). Using the xreference column within the joomla content table, the consumer must assign the content to some specific id within the category selected (because Model_Blog can contain id = 1, in addition to Model_Product can).

So every article in Joomla includes a unique mixture of catid and xreference. Now I wish to bind that one-to-one regards to my Kohana ORM models (e.g. Model_Blog), however the standard Kohana ORM $_has_one property only supports foreign secrets composed of 1 column rather than multiple AFAIK.

I attempted the next, which, obviously, does not work:

protected $_has_one = array(
  'content' => array('model' => 'cms_content', 'foreign_key' => 'xreference', 'catid' => '1')
);

Can anybody advise me regarding how to bind this relationship properly?

Following a research within the source code, I discovered that Kohana ORM does not offer the feature I referred to and that i needed to extend the ORM module (that is due to Kohana's character, simple :)), to implement multi-column FK's.

class ORM_Modified extends ORM {
    public function __get($column) {
        if (isset($this->_has_one[$column])) {
            $model = $this->_related($column);
            $pk = $this->pk();

            // Use this model's primary key value (if no value set) and foreign model's column(s)
            if(!is_array($this->_has_one[$column]['foreign_key'])) {
                $col = ;
                $model->where($model->_object_name.'.'.$this->_has_one[$column]['foreign_key'], '=', $pk);
            } else {
                foreach($this->_has_one[$column]['foreign_key'] as $col => $value) {
                    $model->where($model->_object_name.'.'.$col, '=', $value == null ? $pk : $value);
                }
            }
            $model->find();

            return $this->_related[$column] = $model;
        } else {
            return parent::__get($column); 
        }
    }
}

Now I'm able to define a range of posts which make up the foreign type in the connection using the following syntax:

protected $_has_one = array(
    'content' => array('model' => 'cms_content', 'foreign_key' => array('xreference' => null, 'catid' => '1'))
);

Please be aware that my solution only is applicable to some 1-to-1 relationship, because during my situation you shouldn't have to implement it for 1-to-many, although I suspect this could need a similar modification