public function getActiveCountries()
{
        return $this->Country->find(
                'list',
                array(
                        'joins' => array(
                                array(
                                        'table' => 'members',
                                        'alias' => 'Member',
                                        'type' => 'inner',
                                        'conditions' =>
'Member.country_id = Country.id'
                                )
                        ),
                        'group' => array('Country.id')
                )
        );
}

On Jun 14, 2:46 am, cricket <zijn.digi...@gmail.com> wrote:
> On Jun 12, 8:49 pm, calvin <cal...@rottenrecords.com> wrote:
>
>
>
>
>
> > Ah, I misunderstood you. I think you should be able to just use the
> > 'join' and 'group' keys, e.g.:
>
> > $countries = $this->Country->find('list', array(
> >   'joins' => array(
> >     array(
> >       'table' => 'cake_members',
> >       'alias' => 'Member',
> >       'type' => 'inner',
> >       'foreignKey' => 'Member.country_id'
> >     )
> >   ),
> >   'group' => array('Country.id')
> > ));
>
> > I think that should work. Or you may need to use the 'conditions'
> > parameter in the 'joins' array instead of the 'foreignKey' parameter.
>
> > Unfortunately, the 'joins' parameter is not documented in the Cookbook
> > for find(). It's only mentioned in the subQuery example using
> > buildStatement(), but that's not necessary.
>
> Thanks. I did try mucking about with the joins option but nothing was
> working for me. I think I had the syntax wrong but I probably had
> other errors, too. This looks correct to me after cross-checking
> elsewhere, but still no joy. Here's my method using your example:
>
> public function getActiveCountries()
> {
>         return $this->Country->find(
>                 'list',
>                 array(
>                         'joins' => array(
>                                 array(
>                                         'table' => 'members',
>                                         'alias' => 'Member',
>                                         'type' => 'inner',
>                                         'foreignKey' => 'Member.country_id'
>                                 )
>                         ),
>                         'group' => array('Country.id')
>                 )
>         );
>
> }
>
> result:
>
> Warning (512): SQL Error: 1054: Unknown column 'Array' in 'on
> clause' [CORE_1.2.7/cake/libs/model/datasources/dbo_source.php, line
> 526]
>
> Query: SELECT `Country`.`id`, `Country`.`name` FROM `countries` AS
> `Country` inner JOIN members AS `Member` ON (Array) WHERE 1 = 1 GROUP
> BY `Country`.`id`
>
> The syntax looks good to me. The joins option should be an array with
> a separate array for each join. I'm going to dive back into the model
> and dbo_* classes to see if I figure it out.

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