Hi everybody,
I have used new yii 1.1.1 and I have had problem when I try access models by models like the old version. For example:
I have
$criteria->join = "INNER JOIN PRODUTO ON produto.IDPRODUTO = t.IDPRODUTO";
$criteria->condition = "t.IDPEDIDO = $model->idpedido";
$produtopedido = produtopedido::model()->findAll($criteria);
When I try access it in my view $produtopedido->idpedido is returning null. In old versions of yii I could access using this way.
In case a have used foreach for tracking my array, foreach($produtospedido as $n=>$prod) and I use $prod->idpedido, but nothing too.
Could somebody help me?
Page 1 of 1
ActiveRecord access Access related models from main model
#2
Posted 23 April 2010 - 12:50 AM
I assume 'idpedido' is a relation in the $model AR class? If it is then how do you initiate $model object?
#3
Posted 23 April 2010 - 07:26 AM
Vince., on 23 April 2010 - 12:50 AM, said:
I assume 'idpedido' is a relation in the $model AR class? If it is then how do you initiate $model object?
Hi Vince,
Yes I assumed idpedido like a relation. I initialize my $model in my controller and I pass $model in render's array and create/update array. The variable is filling because I have try "var_dump($model)".
Regards,
Jorge Teles
Systems Analist
Systems Analist
#4
Posted 23 April 2010 - 07:56 AM
if the idepedido is a relation in the $model then make sure you initiate the relation when initiating the $model.
So, If you do:
So, If you do:
$model = ModelName::model()->with(array('ipdedido'))->findAll();
foreach($model as $data)
{
// now call $data->ipedido
}
#5
Posted 23 April 2010 - 09:19 AM
Vince., on 23 April 2010 - 07:56 AM, said:
if the idepedido is a relation in the $model then make sure you initiate the relation when initiating the $model.
So, If you do:
So, If you do:
$model = ModelName::model()->with(array('ipdedido'))->findAll();
foreach($model as $data)
{
// now call $data->ipedido
}
Thanks Vince,
But when I want access the related table, for example, $model->pedido->produtopedido->idproduto. I have already define my relations on model pedido with produtopedido.
Does method above work or would work? I have been tried and at now, nothing!
Thanks.
Jorge Teles
Systems Analist
Systems Analist
#6
Posted 23 April 2010 - 09:34 AM
jorteles, on 23 April 2010 - 09:19 AM, said:
Thanks Vince,
But when I want access the related table, for example, $model->pedido->produtopedido->idproduto. I have already define my relations on model pedido with produtopedido.
Does method above work or would work? I have been tried and at now, nothing!
Thanks.
But when I want access the related table, for example, $model->pedido->produtopedido->idproduto. I have already define my relations on model pedido with produtopedido.
Does method above work or would work? I have been tried and at now, nothing!
Thanks.
Hi,
I found the solution/problem. I have defined wrong relation(m:n). I have 3 tables: pedido, pedidoproduto and produto. I was defining relation between pedidoproduto and produto like HAS_MANY, where I would define BELONGS_TO. Now it works.
Thanks.
Jorge Teles
Systems Analist
Systems Analist
Share this topic:
Page 1 of 1

Help















