Subject: associations dont work
Hi, i'm trying to make this code work, but without success:
class Escritorio extends ActiveRecord\Model { static $belongs_to = array ( array('cadastro','foreign_key'=>'cadastro_id','class_name'=>'Cadastro'), array('endereco','foreign_key'=>'endereco_id','class_name'=>'Endereco') );
}
To debug i call this code: $E = Escritorio::all(); echo $E->cadastro->nome; print_r($E);
the result is:
Array ( [0] => Escritorio Object ( [errors] => [attributes:ActiveRecord\Model:private] => Array ( [id] => 1 [endereco_id] => 1 [cadastro_id] => 1 ) [__dirty:ActiveRecord\Model:private] => Array ( ) [__readonly:ActiveRecord\Model:private] => [__relationships:ActiveRecord\Model:private] => Array ( ) [__new_record:ActiveRecord\Model:private] => ) )
Someone know what's happing? My activerecord is integrated with CI through Matthew Machuga article.
ok, it's working.
although i dont understand how we can use $E0->cadastro->nome, if $E dont have object cadastro in properties.
(1-1/1)
June 27 2010
December 21, 2012
Subject: associations dont work
Hi, i'm trying to make this code work, but without success:
class Escritorio extends ActiveRecord\Model {
static $belongs_to = array
(
array('cadastro','foreign_key'=>'cadastro_id','class_name'=>'Cadastro'),
array('endereco','foreign_key'=>'endereco_id','class_name'=>'Endereco')
);
}
To debug i call this code:
$E = Escritorio::all();
echo $E->cadastro->nome;
print_r($E);
the result is:
Array ( [0] => Escritorio Object ( [errors] => [attributes:ActiveRecord\Model:private] => Array ( [id] => 1 [endereco_id] => 1 [cadastro_id] => 1 ) [__dirty:ActiveRecord\Model:private] => Array ( ) [__readonly:ActiveRecord\Model:private] => [__relationships:ActiveRecord\Model:private] => Array ( ) [__new_record:ActiveRecord\Model:private] => ) )
Someone know what's happing?
My activerecord is integrated with CI through Matthew Machuga article.