Use "contain"

There is a chapter in the cookbook how to get only the records from related
models and not pull all the un-necessary info.

Dave



-----Original Message-----
From: Alastair [mailto:[email protected]] 
Sent: July-07-09 10:31 PM
To: CakePHP
Subject: More HABTM questions - querying data


Robert P kindly solved a problem I was having with updating records in a
HABTM relationship so many thanks to him for that!

I'm now trying to query the data but have added an additional model to my
system, Regions. So it looks something like:

Members HasAndBelongsToMany County
County BelongsTo Region (and Region hasMany County)

I'm trying to return members that belong to Region.id = 1 and am using this
to do so:

$members = $this->Member->County->Region->find('all', array ('conditions' =>
array('Region.id' => $id), 'recursive' => 2));

This does return all members belonging to Region 1 but it also returns a
whole lot of other information with it. Is there any way I can construct a
query that literally just returns the corresponding members?

The above returns the following data: http://bin.cakephp.org/saved/48057

which includes County and Region data and in this instance, I don't need it.
I'll live with it if I need to but I'd rather I didn't have to! Removing
'recursive' => 2 results in just the Region and County data being returned.

Many thanks,

Alastair


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to