Well the manual might be slightly misleading. The text states that
Containable can "filter" the associated data. It is the example output
that is wrong (AFAIK), showing data as from a join.

Containable does "nothing more" than filter the returned data, model
for model. It does not mimic joins. I am not saying this is a fault or
a shortcoming of Containable... it is just the way it is designed and
it does it's job well.

We answered a question yesterday, giving the exact example of Posts
and Comments... funny. It is here, along with links to some code and
articles showing how to set up something like "Joinable".
http://groups.google.com/group/cake-php/browse_thread/thread/43b4a9fcc18cf442

The alternative is to do some array-looping in php to remove unwanted
results. This is fine for small datasets but gets very slow when you
get up into thousands of results.

/Martin


On Aug 18, 7:55 pm, channel5 <[email protected]> wrote:
> Hi All
>
> I am working through examples of containable and applying conditions
> to the results.
>
> I have a basic blog example running, where Posts can have many
> comments.
>
> I'm trying to use contain with conditions so I can pick out only posts
> that have been commented on by a particular user.
>
> Here is my test function from my controller:
>
>         function test() {
>                 $result =  $this->Post->find('all',array('contain' => 
> 'Comment.name
> = "Howard"'));
>                 debug($result);
>         }
>
> I would expect the debug output in my view to only contain Posts which
> user Howard has commented on.. however here are the results I get:
>
> Array
> (
>     [0] => Array
>         (
>             [Post] => Array
>                 (
>                     [id] => 1
>                     [name] => First post
>                     [date] => 2009-08-13 15:01:00
>                     [content] => This is our first blog post, how
> exciting.
>                     [user_id] => 1
>                 )
>
>             [Comment] => Array
>                 (
>                     [0] => Array
>                         (
>                             [id] => 1
>                             [name] => Howard
>                             [content] => Lovely post, really lovely
> post.
>                             [post_id] => 1
>                         )
>
>                 )
>
>         )
>
>     [1] => Array
>         (
>             [Post] => Array
>                 (
>                     [id] => 2
>                     [name] => Our second post
>                     [date] => 2009-08-14 10:11:00
>                     [content] => Our second post
>                     [user_id] => 1
>                 )
>
>             [Comment] => Array
>                 (
>                 )
>
>         )
>
> So as you can see it is still returning ALL posts yet only attaching
> comments if they were made by Howard.
>
> This isn't the behaviour I was expecting, as the example code shown 
> athttp://book.cakephp.org/view/474/Containableclaims it should exclude
> all Posts without comments by the specified user.
>
> I am hoping someone can point me in the right direction here.
>
> Thanks
> c5
--~--~---------~--~----~------------~-------~--~----~
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