how to force to refresh value of model in yii

19,217

Solution 1

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

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

Solution 2

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.

Solution 3

In Yii2 its just a simple

unset($model->relation);

so in this case unset($a->b)

Share:
19,217

Related videos on Youtube

liysd
Author by

liysd

Updated on February 03, 2020

Comments

  • liysd
    liysd about 4 years

    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().

Related