Yii Framework Forum: 关于Ar操作时Afterdelete的疑惑 - Yii Framework Forum

Jump to content

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

关于Ar操作时Afterdelete的疑惑 Rate Topic: -----

#1 User is offline   netljc 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 29-May 11

Posted 04 December 2012 - 05:05 AM

AR操作时通过先通过findByPk之后再delete可以调用afterDelete方法,而直接使用deleteAll无法调用afterDelete方法,这是怎么回事啊!难道一定要通过主键删除数据时才能调用afterDelete方法吗?
0

#2 User is offline   hehbhehb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 24-February 12

Posted 04 December 2012 - 08:26 PM

是的.
afterDelete是在delete中被调用, 而deleteAll并没有调用delete,所以不会调用afterDelete.
delete是一个真正ar实例的方法; deleteAll虽然也是一个ar的方法,但是这个ar的属性并未被populate, 实际上可看成是静态函数, 无法调用delete, 也就没有调用afterdelte了,这样做可能是出于效率的原因.
1

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