Hello,
In my database table, I have price1, price2, price3
I want to return a field called price that is one of those above.
if group = "A"
price = price1
if group = "B"
price = price2
so when I run my query, I can just reference field price
Thanks
Page 1 of 1
Is It Possible To Return A Calc Field In Model
#2
Posted 18 February 2013 - 02:05 PM
in your model,
in your view;
or in your view,
public $price;
public function afterFind(){
if ($this->group === 'A'){
$this->price = $this->price1;
} else if ($this->group === 'B'){
$this->price = $this->price2;
} else {
$this->price = $this->price3;
}
}
in your view;
echo $this->price;
or in your view,
'value'=>"($data->group === 'A')?$data->price1:(($data->group === 'B')?$data->price2:$data->price3)",
when i ask, if my question does not make sense, don't blame on me, coz i am new here to learn yii;
when i answer, if my answer does not make sense, don't blame on me, coz i am trying to answer to be answered;
ok, i'm covered to mess up and fooling around, yeehaw ...
when i answer, if my answer does not make sense, don't blame on me, coz i am trying to answer to be answered;
ok, i'm covered to mess up and fooling around, yeehaw ...
#3
Posted 18 February 2013 - 02:40 PM
Thank you,
I like the model approach because I want to ensure the correct field is always returned.
I was doing this using raw sql and doing a price1 as price
I like the model approach much better.
Is there any drawbacks?
I like the model approach because I want to ensure the correct field is always returned.
I was doing this using raw sql and doing a price1 as price
I like the model approach much better.
Is there any drawbacks?
Regards,
Frank
Frank
Share this topic:
Page 1 of 1

Help













