yiisoft/yii — pull request #2586 by louis89 (2013-06-24 21:00:58+00:00)
Title: Added the event afterFindWithAttributes to CActiveRecord.php and an asso...

This PR adds a new event to CActiveRecord called onAfterFindWithAttributes and an associated event handler in CActiveRecordBehavior. This event is identical to onAfterFind except that the CEvent's params property is set to the value of the argument of the parameter called arguments of populateRecord method of CActiveRecord. It would be cleaner if this was done using the onAfterFind method, but that would have broken BC.

Normally additional attributes passed to the populateRecord method are ignored and there is no way to hook these attributes without extending CActiveRecord and overriding either the populateRecord method or instantiate method of CActiveRecord. The onAfterFindWithAttributes event creates this missing hook.

In my case I have several queries which select additional values from either joined tables or sub queries that do not have attributes in the CActiveRecord and are therefor silently ignored by populateRecord. However, those additional values are important to the configuration of the CActiveRecord instance. Using this implementation it is possible to appropriately configure a CActiveRecord instance based on values returned by a find query that are not defined as table columns, properties or getters/setters in the CActiveRecord.