I'm having some problems getting Containable to work for a particular model. I don't know if it's the way I'm using it or my associations/schema are no good. The site I'm working on can have several types of users, so I've set it up like so (simplified):
User: var $hasOne = array( 'Admin', 'Professional', 'Organisation' ); var $hasMany = array( 'Publication' ); Professional: var $belongsTo = array('User'); Organisation: var $belongsTo = array('User'); Publication: var $belongsTo = array('User'); So, the professionals, organisations, and publications tables all have a user_id field. In my PublicationsController, I'd like to select some info from that model, plus some basic info about either the Professional or Organisation which owns it. However, it's the User that the Publication belongsTo. Is there some way to grab the Pro or Org info derived from the Publication.user_id? $criteria = array( 'conditions' => array( 'Publication.id' => 32 ), 'fields' => array('id', 'title', 'slug', 'thumbnail'), 'contain' => array( 'User' => array( 'Professional' => array( 'fields' => array( 'first_name', 'last_name' ) ), 'Organisation' => array( 'fields' => array( 'name' ) ) ) ) ); return $this->Showcase->find('first', $criteria); // this is an element method, btw I've also tried adding 'fields' => array('id') to each of those. But I still can't get cake to select from the pro or orgs tables. All I get is the User.id: SELECT `Publication`.`id`, `Publication`.`title`, `Publication`.`slug`, `Publication`.`thumbnail`, `User`.`id` FROM `publications` AS `Publication` LEFT JOIN `users` AS `User` ON (`Publication`.`user_id` = `User`.`id`) WHERE `Publication`.`id` = 32 LIMIT 1 Is what I'm trying to do even possible? Is my schema wrong-headed? Should I just make a second query on the Professional or Organisation models using the returned user_id? BTW, I realise that the Publication is either related to a Professional *or* an Organisation. I was hoping that, if Containable will let me do what I'm trying to do, the data array for one of those will simply be empty. Correct me if I'm wrong about that. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" 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 -~----------~----~----~----~------~----~------~--~---