You Have 2 chance to accomplish this task 1. You can build fake field in your model afterFind() function function afterFind( $result ) { $result = parent::afterFind( $result ); foreach( $result as $k => $v ) { $result[$k]['Table']['thumb_url'] = 'thumb_' . @$v['Table']['image']; } return $result; }
2. You can build your fake field with findAll $data = $this->Table->findAll(null, "*, CONCAT('thumb_', image) AS thumb_url"); die(pr($data)); Attention in case 2 the field is not added in the Table array but in array apart. See the pr output HTH > -----Messaggio originale----- > Da: cake-php@googlegroups.com > [mailto:[EMAIL PROTECTED] Per conto di laptop > Inviato: giovedì 31 maggio 2007 6.51 > A: Cake PHP > Oggetto: adding extra fields when reading a model > > > Hi, > > Is there a way to add a field to a model which is the result > of an SQL function. My scenario is that I have an image_url > field, the thumb of the image_url is also stored in the same > directory with '_thumb' > appended before the index. > > ie bradcraig.jpg would become bradcraig_thumb.jpg > > Is there a way I can include a SQL function when retrieving > the model?? The SQL to calculate it is below.. > > SELECT 'images/bradcraig.jpg' AS image_url, > CONCAT(SUBSTRING_INDEX('images/bradcraig.jpg', '.', 1), > '_thumb.', SUBSTRING_INDEX('images/bradcraig.jpg', '.', -1)) > AS thumb_url; > > Thanks > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---