Morning mate,
I had this problem to begin with.
By turning debug to 2, which you have done, you can see how Cake
retrieves it's HABTM associated data. I'm pretty sure it doesn't
actually do it using a single array so applying conditions for both
`This` and `That` will not work.
When I want to grab all the `That`s that have a relationship to a
`This` model with id of X I either:
That->setId(X);
data = That->read();
data_this = data['This']
If that makes sense.
However, I'm still using Cake 1.1.x.x.x and so the Pagination
component / helper combo doesn't play well with sub arrays. So i'm a
bit cheeky and have written a very small function in my That model
that returns all the This id's related to the That model with id X.
Then I can do
That->setId(X);
conditions = array(
'This.id' => That->getThisIds()
)
data = This->findAll();
And you now have an array of This's that belong to that That model :)
Also, I take a conditions array in my getThisIds function so you can
do refine your query by things like That.active = Y
HTH,
mikee
p.s. If anyone had a better way of doing this I would be well up for
hearing it! A bit of a moot point as I'm going to move to Cake 1.2 in
the next project or so and I hear there is quite good pagination
inherent there.
On 29/11/06, TWIOF <[EMAIL PROTECTED]> wrote:
>
> My latest problem: I can get data from my HABTM with:
> $this->set('x', $this->thing->findall())
>
> but can't when using a more specific custom model:
> $conditions = "(This.that_id = '1') AND (That.active = 'y')";
> $fields = array('This.name', 'That.name');
> return $this->findAll($conditions, $fields, null, null, null, 0);
>
> with "this" and "that" being joined by habtm.
>
> When the sql that is produced the first method is fine, but with the
> second method it doesn't join the habtm stuff.
>
>
> How do I do this, I'm building a search feature and want to search by
> with basic info from HABTM relationships
>
>
> Thanks in advance
>
> TWIOF
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" 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
-~----------~----~----~----~------~----~------~--~---