I am looking for help specific to my question as I cant quite seem to get it right from the Kohana docs or googling.
I have 2 tables:
contents
id
uri
title
template_id
templates
id
title
I am trying to return all data for a contents
row that has a matching uri.
Currently I have two models: Content and Template.
Content
class Model_Content extends ORM {
protected $_table_name = 'contents';
protected $_has_one = array('template' => array());
....
Template
class Model_Template extends ORM {
protected $_table_name = 'templates';
protected $_belongs_to = array(
'content' => array()
);
Then in my controller:
$item = ORM::factory("Content")->get_by_uri($uri);
which points to:
$this->where("uri", "=", $uri)->find();
This returns the data from the content table correctly but how can i bring in the template name from the template table?
Thanks for help with this.
$item->template
is all you need. And dont forget to check model for existance: if ($item->loaded())
.