Kohana ORM Aliasing and "Trying to get property of non-object"
Posted
by Toto
on Stack Overflow
See other posts from Stack Overflow
or by Toto
Published on 2010-05-11T19:12:00Z
Indexed on
2010/05/11
19:14 UTC
Read the original article
Hit count: 462
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
© Stack Overflow or respective owner