Thanks.  Looks like progress, but now error is:

 Model "Product" is not associated with model "Group" [CORE/cake/libs/
model/behaviors/containable.php, line 317]

--
Product has one Group through Collection:

class Product extends AppModel {

        var $name = 'Product';
        var $actsAs = array('Containable');
        var $belongsTo = array(
                        'Collection' => array('className' => 'Collection',
                                                                'foreignKey' => 
'collection_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        ),

--

class Collection extends AppModel {

        var $name = 'Collection';
        var $order = 'Collection.name';

        var $actsAs = array('Containable');

        var $belongsTo = array(
                        'Group' => array('className' => 'Group',
                                                                'foreignKey' => 
'group_id',
                                                                'conditions' => 
'',
                                                                'fields' => '',
                                                                'order' => ''
                        )
        );

Any other ideas?

On Dec 14, 6:06 pm, Tonu Tusk <lvot...@googlemail.com> wrote:
> 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 <todd.mcgr...@gmail.com> 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to