I am using an afterFind function to modify data from a find function. It works fine. If I move the afterFind function into a behavior (in a plugin) it still works, but only when the model of interest is the primary model, i.e. it isn't called when the model belongsTo another model. Is there any way round this? I'm using cake 1.3.4. This is a simplified version of the behavior:
class ChemicalStructureBehavior extends ModelBehavior {
function afterFind(&$model, $results, $primary) {
foreach ($results as &$unit) {
// format chemical formula (with subscripts)
$unit[$model->alias]['chemical_formula_formatted'] = preg_replace('/([0-9]+)/i', '<sub>$1</sub>', $unit[$model->alias]['chemical_formula']);
}
return $results;
}
}