AfterFind : A bug or a feature ?

i got a question about this kind of code :

Test::model()->attachEventHandler(‘onAfterFind’,array($this,‘testingBefore’));

Test::model()->attachEventHandler(‘onAfterFind’,array($this,‘testingAfter’));

Test::model()->findAll();

i thought that this will call

testingBefore()

and

testingAfter()

but after a bit debugging i figure out that it’ll only call testingBefore() since findAll() create a new object wish does not have an event handler for onAfterFind.

my question is this a desired feature ?

if not may be you should update CActiveRecord (line:1493) with something like :

$record->afterFind(); 
  • $this->afterFind())

or

  • $record->_e=$this->_e;

    $record->afterFind();

Thanks :)

Since the event handlers are defined, and findAll is called, on the shared singleton, my guess is that the framework is ok. I may be wrong, though.

Is there a possibility you defined an afterFind() method without the required call to the parent?

/Tommy (not a team member)

Edit:

I verified that I was wrong.

One way to have the event raised would be to attach it to a model instance in the afterFind() method.




protected function afterFind()

{

  $this->onAfterFind = array(SomeClass, 'testingAfter');

  parent::afterFind();

}