Hi, you can only specify the fields for the model that you are callng
the "find" method on in the 'fields' attribute in the parameter list
passed to the method call.
You need to specify the fields you want returned in the dataset
controlled by the containable behaviour in the 'contain' variable
itself.
e.g in your parameter array to the find call you would do
'contain' => array('Collection' => array('fields' => array
('Collection.name', 'collection.group_id',)), 'Group' => array
('fields' => array('Group.name'))
also make sure all your model relationships are setup and also the
actsAs variable in the Product model has 'Containable' set.
On Dec 14, 8:25 pm, Todd McGrath <[email protected]> wrote:
> Hello,
>
> Having trouble figuring out how to construct a query such as this:
>
> "SELECT products.*, groups.* FROM products Inner Join collections ON
> products.collection_id = collections.id Inner Join groups ON
> collections.group_id = groups.id WHERE products.name LIKE '%" .
> $searchstring . "'"
>
> Products belongsTo Collections and Collections belongsTo Groups
>
> I'm trying to use find all with conditions and fields and recursive,
> but no luck. Example:
>
> $this->set('products', $this->Product->find('all', array
> ('contain' => array('Collection', 'Group'), 'conditions'=>array
> ('Product.name LIKE ' => $searchstring), 'recursive'=>3, 'fields' =>
> array('Product.name','Collection.name', 'Collection.group_id',
> 'Collection.group_id','Group.name') )));
>
> but, the error is:
> Warning (512): SQL Error: 1054: Unknown column 'Group.name' in 'field
> list' [CORE/cake/libs/model/datasources/dbo_source.php, line 512]
>
> How can I obtain the Group field data through Collections when
> querying Products?
>
> Todd
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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