Kohana 3: getting related data from an ORM model

When using Kohana 3's ORM models, what is the best way to get data from fields of related models? For example, I have an employee, who has one company, and has many assignments. How would I go about getting data from fields in the company model and assignment model(s) (i.e. in a has_one and a has_many relationship)?EDIT: as requested, here are the models in question.User Model\[code\]class Model_User extends ORM { protected $_table_name = 'user'; protected $_primary_key = 'id'; protected $_primary_val = 'username'; protected $_has_many = array( 'task' => array( 'model' => 'task', 'foreign_key' => 'user', ), ); protected $_belongs_to = array( 'company' => array( 'model' => 'company', 'foreign_key' => 'company' ), );\[/code\]Task Model\[code\]class Model_Task extends ORM { protected $_table_name = 'tasks'; protected $_primary_key = 'id'; protected $_primary_val = 'name'; protected $_belongs_to = array( 'project' => array( 'model' => 'project', 'foreign_key' => 'project' ), 'user' => array( 'model' => 'user', 'foreign_key' => 'user' ), );\[/code\]Company Model\[code\]class Model_Company extends ORM { protected $_table_name = 'companies'; protected $_primary_key = 'id'; protected $_primary_val = 'name'; protected $_has_many = array( 'user' => array( 'model' => 'user', 'foreign_key' => 'company' ), );}\[/code\]Code Throwing Error, From Controller\[code\]$users = ORM::factory('user')->find_all();$list = array();foreach($users as $user) { $list[$user->id] = array( 'username' => $user->username, 'email' => $user->email, 'company' => $user->company->name //error:Trying to get property of non-object )}\[/code\]
 
Back
Top