hi

I think what you want to do is 'filter' out Users based on a condition
on the Comment field, is that correct ?

Like retrieve only users that have a comment WHERE title = 'More on
Gwoo'

if so I think you have to resort to temporarily binding a hasOne
relationship to the User Model like so :

this->User->bindModel(
                                array('hasOne' =>
                                                array('CommentFilter' =>
                                                                        array(
                                                                                
        'className' => 'Comment',
                                                                                
        'conditions' => array('title' => 'More on Gwoo')
                                                                                
)
                                                                        )
                                                                )
                                                        );

then use the CommentFilter association in the 'find' call

$this->User->find('all',array('conditions' =>
array('CommentFilter.title' => 'More on Gwoo')));

I think it does the trick but I'd like to stand corrected if I'm
wrong.

What I don't know how to do is how to filter with multiple conditions
like :

Comment.title = 'More on Gwoo' OR  Comment.title = 'On Gwoo the
Kungwoo'

since the hasOne assocation will only (hum ...) associate one record
that we can then filter on. Anyone on this one ?

What I often do is use Set::extract (with the Xpath syntax) to filter
my result sets.

If you just want to omit some records from the associated results you
can use the containable behavior and do something like this :

$this->User->contain('Comment' => array('conditions'
=>array( 'Comment.title' => 'More on Gwoo')));

a find('all') will give you all users but will have filtered the
Comments

I hope I'm right in all I'm saying, this all seems to work for me.

hth

thomas


On Jun 10, 10:45 am, teum <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a problem with the hasMany relationship. Let's take the example
> given by the cookbook : a User hasMany Comments.
>
> //Sample results from a $this->User->find() call.
>
> Array
> (
>     [User] => Array
>         (
>             [id] => 121
>             [name] => Gwoo the Kungwoo
>             [created] => 2007-05-01 10:31:01
>         )
>     [Comment] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 123
>                     [user_id] => 121
>                     [title] => On Gwoo the Kungwoo
>                     [body] => The Kungwooness is not so Gwooish
>                     [created] => 2006-05-01 10:31:01
>                 )
>             [1] => Array
>                 (
>                     [id] => 123
>                     [user_id] => 121
>                     [title] => More on Gwoo
>                     [body] => But what of the ‘Nut?
>                     [created] => 2006-05-01 10:41:01
>                 )
>         )
> )
>
> The find() call will result in two separate queries (tell me if I'm
> wrong but this is what I can see in my program) so how to specify a
> condition related to a field of the comments table using the find()
> method ?
>
> If it is not clear enough I can reformulate :)
>
> Thanks in advance
--~--~---------~--~----~------------~-------~--~----~
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