Yii Framework Forum: Update/delete Commands Ignore Alias. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Update/delete Commands Ignore Alias. Rate Topic: ***** 1 Votes

#1 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 386
  • Joined: 08-June 10
  • Location:France (Ile-de-France/Val d'Oise)

Posted 03 July 2013 - 06:48 PM

Hi

updateAll ignores criteria defined on the model using scopes, so I did something like the following:


$criteria=new CDbCriteria();

MyAR::model()->scope1()->scope2()->applyScope($criteria);


MyAR::model()->updateAll(array('fieldtoupdate'=>'newvalue'),$criteria);



However that fails as the criteria use the 't' alias and that alias is not applied when the UPDATE command is constructed. I am using 1.1.12, but this is also true in 1.1.13.




The workaround is to add one line before:


 MyAR::model()->getDbCriteria()->alias=MyAR::model()->tableName();


$criteria=new CDbCriteria(); 

MyAR::model()->scope1()->scope2()->applyScope($criteria);

MyAR::model()->updateAll(array('fieldtoupdate'=>'newvalue'),$criteria);





Edit: I have now written a Wiki for this: http://www.yiiframew...ll-with-scopes/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users