[color="#8B0000"]$dadosPessoais->logradouro[/color] Doesn’t exist yet because was create with $dadosPessoais->new DadosPessoais();
But when I got it with $dadosPessoais = DadosPessoais::model()->with(/****/)->find( /*****/ ) it works perfecly except but the name field issue (which I can bypass this).
So… How can I access a BELONGS_TO variable for a newly created model?
It doesn’t matter if it does not exists, it will be blank anyway, But this error is annoying…
In the __contruct() method of my model I can inject the field only when they are created.
public function __construct($attribute = array(), $scenario='')
{
if ($this->getIsNewRecord())
{
$this->logradouro = new Logradouro;
$this->telefones[0] = new Telefone;
$this->telefones[1] = new Telefone;
$this->telefones[2] = new Telefone;
$this->tituloEleitor = new TituloEleitor;
$this->dados_comerciais = new DadosComerciais;
}
parent::__construct($attribute, $scenario);
}
The reason for the ‘if’ statement is because it overwrites this find() method: