Henrique Mascarenhas Sat Jan 08 05:49:36 -0500 2011

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.


Henrique Mascarenhas Sat Jan 08 10:06:06 -0500 2011

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)