foreach ($team->users as $user) ...
$teamname = $user->team->name;
// get the first array element $team = reset($user->team); echo $team->name;
Harro Verton wrote on Monday 26th of September 2011:Relations are always array's, even it there is only one object in them. So try// get the first array element $team = reset($user->team); echo $team->name;
protected static $_belongs_to = array( 'team' => array( 'key_from' => 'team', 'model_to' => 'Model_Team', 'key_to' => 'id', 'cascade_save' => true, 'cascade_delete' => false, ) );
protected static $_has_many = array( 'users' => array( 'key_from' => 'id', 'model_to' => 'Model_User', 'key_to' => 'team', 'cascade_save' => true, 'cascade_delete' => false, ) );
Harro Verton wrote on Monday 26th of September 2011:If the key is 'team', you have the problem that the name of the relation is the same as a column name, so $object->team will return the column value, and will not fetch the related object.
_belongs_to = array('team');
_has_many = array('users')
It looks like you're new here. If you want to get involved, click one of these buttons!