For the first query that does get the related categories, does CakePHP
perform a second query right after the first one?
I'm thinking that the first query "works" because it is actually
performing two separate queries (or more depending on relationships
and recursive setting) and CakePHP is only applying the 'fields'
parameter to the first query. So in the first query, the join hasn't
occurred yet (which should happen in the second query), which may be
why you get that error. However, one possible solution is to add the
Containable Behavior in the Project model, for example:
class Project extends AppModel {
var $name = 'Project';
var $actsAs = array('Containable');
....
}
Then try adding a 'contain' in your find options which is set to an
array containing the list of models you wish to only join with. Using
'contain' means you don't need to set 'recursive.' For example:
$this->set('visibleprojects',
$this->Project->find(
'all',
array(
'contain' => array
('Category'),
'conditions'=>array
('Project.visible'=>1),
'fields'=>array(
'Project.title','Category.name'
)
)
)
);
I'm not sure though if you've tried that or not already.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---