Yii Framework Forum: AR isNewRecord and AfterSave - Yii Framework Forum

Jump to content

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

AR isNewRecord and AfterSave Rate Topic: -----

#1 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 04 July 2009 - 06:16 AM

In CActiveRecord class the attribute isNewRecord is set to false after the method afterSave(). Why? In my code in afterSave() method I expect this attribute to be already false, but it is not. E.g, I need to update some attributes of the model after this model is saved, and for this operation I use model's id which is set only after the model is saved.


0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,900
  • Joined: 04-October 08
  • Location:DC, USA

Posted 04 July 2009 - 07:47 AM

This is done purposely so that in afterSave(), you can tell whether it is called in an insert() or update(). You can explicitly set this property to be false if you want in afterSave().
0

#3 User is offline   olafure 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 04-March 09
  • Location:Iceland

Posted 04 July 2009 - 03:11 PM

If you expect it to be false, just assume it - it would be false in any case!
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 05 July 2009 - 03:10 AM

Yes, I get it, thanks and sorry :)
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