Kohana ORM Aliasing and "Trying to get property of non-object"
- by Toto
I have the following tables in the database:
teams:
id
name
matches:
id
team1_id
team2_id
I've defined the following ORM models in my Kohana application:
class Match_Model extends ORM {
protected $belongs_to = array('team1_id' => 'team', 'team2_id' => 'team');
}
class Team_Model extends ORM {
protected $has_many = array('matches');
}
The following code in a controller:
$match = ORM::factory('match',1);
echo $match->team1_id->name; /* <-- */
Is throwing the following error on the linke marked with /* <--- */:
Trying to get property of non-object
The framework is yielding the value of the foreign key instead of a reference to a Match_Model instance as it should (giving the has_many and belongs_to properties stated).
Am I missing something?
Note: Just in case, I've added the irregular plural 'match' => 'matches' in application/config/inflector.php