That's just the way CakePHP indexes the associations.  I agree it was
not what I expected at first, but it is not difficult to work with.
My personal solution is to have the following afterFind() in the app/
app_model.php , and then any particular model can have a
_attachAttributes function to deal with the actual row data

app/app_model.php:
        function afterFind( $results )
        {
                //$this->log('afterFind on '.$this->name .' with results:
'.print_r($results,true));
                // see if the model wants to attach attributes
                if ( method_exists($this, '_attachAttributes') ){
                        // we want each row to have an array of required 
attributes

                        for ($i = 0; $i < sizeof($results); $i++) {
                                // check if this is a model, or if it is an 
array of models
                                if ( isset($results[$i][$this->name]) ){
                                        // this is the model we want, see if 
it's a single or array
                                        if ( 
isset($results[$i][$this->name][0]) ){
                                                // run on every model
                                                for ($j = 0; $j < 
sizeof($results[$i][$this->name]); $j++) {
                                                        
$this->_attachAttributes( &$results[$i][$this->name][$j] );
                                                }
                                        } else {
                                                $this->_attachAttributes( 
&$results[$i][$this->name] );
                                        }
                                }
                        }

                }

                return $results;
        }

app/models/my_model.php

        function _attachAttributes( &$data_row )
        {
                // set the full name from the first name and surname
                $data_row['_fullname'] = $data_row['firstname'].' '.
$data_row['surname'];
        }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to