I'm also getting this.
I have two models
Project
Category
With a HABTM relationship.
In the Project controller on a find (requesting for "visible" - a bool
in my model) i get related categories out ok:
$this->set('visibleprojects',
$this->Project->find(
'all',
array(
'conditions'=>array('Project.visible'=>1),
'recursive' => 1
)
)
);
However if I try to specify which fields I want
$this->set('visibleprojects',
$this->Project->find(
'all',
array(
'conditions'=>array('Project.visible'=>1),
'recursive' => 1,
'fields'=>array(
'Project.title','Category.name'
)
)
)
);
I get this
Warning (512): SQL Error: 1054: Unknown column 'Category.name' in
'field list'
Apparantly Cake performs a query without the necessary join:
Query: SELECT `Project`.`title`, `Category`.`name` FROM `projects` AS
`Project` WHERE `Project`.`visible` = 1
I'm new to CakePHP so I'm sure I'm making some simple mistake.
I've tried vatious remedies to no avail:
– The HABTM relationship is specified in both models. I'm not sure if
that's considered redundant? so I tried removing one of these
declarations.
– I also tried to specify $uses = array(''Project','Category') in the
controller
I also tried to make the models "Containable"
but really I'm shooting in the dark.
Any insight is very much appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---