Thank you for your response!
The afterFind seems a good solution to me, I will let you know as soon as I tested it. By the way, isn't this a problem more users will have to deal with? Imagine a base model like Item and some models that extend this model like EventItem and NewsItem which have extra fields. Then querying for all models you will also want to have the extra fields for EventItem and NewsItem included. Your trick will do the job! Thanks! Peter On Mar 3, 5:40 pm, "Grant Cox" <[EMAIL PROTECTED]> wrote: > One way would be to have all the possible item types (ie NewsItem, > EventItem) associated, with different conditions. Only those that > match should be loaded (but you will probably get all the keys, and > it'll be a complicated and possibly slow JOIN generated). > > class Item extends AppModel > { > var $name = 'Item'; > var $belongsTo = array( > 'EventItem' => array('className' => 'EventItem', > 'foreignKey' => > 'type_id', 'conditions' => 'Item.type = 0'), > 'NewsItem' => array('className' => 'NewsItem', 'foreignKey' > => > 'type_id', 'conditions' => 'Item.type = 1'), > ); > > } > > other than that you can have something in the afterFind of your Item > model to make a query and load the correct items data. Something > like: > > class Item extends AppModel > { > var $name = 'Item'; > > function afterFind( $results ) > { > 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; > } > > function _attachAttributes( &$data_row ) > { > if ( !empty($data_row['id']) ){ > > switch( $data_row['id'] ){ > case 0: > $event_item = > $this->EventItem->find('EventItem.id'=> > $data_row['type_id']); > $data_row['EventItem'] = > $event_item['EventItem']; > break; > case 0: > $event_item = > $this->NewsItem->find('NewsItem.id'=> > $data_row['type_id']); > $data_row['NewsItem'] = > $event_item['NewsItem']; > break; > } > > } > } > > } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---