Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force to refresh value of model in yii

Tags:

model

yii

let's say I have model A with relation to B.

When I write:

$a = A::model()->findByPK(1);
$a->B->doSomething();

and now B may by changed (by other user for instance). When I write:

$a->B->doSomething(); 

it uses old values of B. What I should do to force to refresh value of B before doSomething().

like image 774
liysd Avatar asked Jul 14 '10 04:07

liysd


2 Answers

Yii provides a refresh() method I think thats what your looking for?

http://www.yiiframework.com/doc/api/CActiveRecord#refresh-detail

like image 112
Luqman Avatar answered Oct 08 '22 00:10

Luqman


You can get a refreshed 'B' value by saying:

$a->getRelated('B',true)->doSomething(); 

The 2nd param "true" asks that yii reload the relation from the database.

like image 44
Karen Zilles Avatar answered Oct 08 '22 00:10

Karen Zilles