On Jun 12, 5:07 pm, cricket <[email protected]> wrote:
> On Jun 11, 12:39 pm, calvin <[email protected]> wrote:
>
> > Wouldn't a simple GROUP BY work?:
>
> > SELECT Country.* FROM cake_countries AS Country JOIN cake_members AS
> > Member ON Country.id=Member.country_id GROUP BY Country.id
> > or
> > SELECT Country.* FROM cake_members AS Member JOIN cake_countries AS
> > Country on Country.id=Member.country_id GROUP BY country_id HAVING
> > COUNT(country_id)>1
>
> This is pretty much what I'm doing now (should have been more clear).
> But the data then needs to be massaged with Set to get in the correct
> format (like find('list')). I was hoping there was some options I
> could pass to find('list') but I'm having a lot of trouble figuring
> what they all are and how to use them. I've been looking at the
> "Complex Find Conditions" section of the manual but aren't getting
> very far.
OK, next iteration: I find all Member.region_ids and then pass that as
a conditon to Region::find('list')
(this is in my Member model)
public function getActiveRegions()
{
$region_ids = Set::extract(
$this->find(
'all',
array(
'fields' => array('DISTINCT Member.region_id'),
'conditions' => array(
'NOT' => array(
'Member.region_id' => null
)
),
'order' => array(
'Member.region_id' => 'ASC'
),
'recursive' => -1
)
),
'{n}.Member.region_id'
);
$regions = $this->Region->find(
'list',
array(
'conditions' => array(
'Region.id' => $region_ids
)
)
);
return $regions;
}
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