Hi,

This should be solvable with with Containable behavior. Or - if you want to
do this with just one query - use the infos you can find in teknoids blog:
http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/
Those infos are also present in the manual for 1.2.

2008/9/9 [EMAIL PROTECTED] <[EMAIL PROTECTED]>

>
> Hello newsgroup!
>
> I have defined the following associations in my models:
> PostModel:  "Post _hasMany_ Comments"
>
> var $hasMany = array(
>  'Comment' => array(
>    'className' => 'Comment',
>    'conditions' => '',
>    'foreignKey' => 'post_id',
>  )
> );
>
> CommentModel:  "Comment _belongsTo_ User"
>
> var $belongsTo = array(
>  'User' => array(
>    'className' => 'User',
>    'conditions' => '',
>    'foreignKey' => 'user_id'
>  )
> );
>
> When I use the query $this->Post->find(), cakephp only uses the
> associations in the PostModel (this is ok).
> This works for simple requests like $this->Post->find() and it returns
> the data array:
> array(
>  'Post' => array(...),
>  'Comment' => array(...)
> )
>
> But is it also possible to include the second association "Comment
> _belongsTo_ User" into the query $this->Post->find()?
> How do I have to define this or other associations in my Post-Model to
> get a data array like this:
> array(
>  'Post' => array(...),
>  'Comment' => array(
>    'User' => array(...)
>  )
> )
>
> I have tried many possibilities in the Post model... still the same
> results!
> The version I used now is a foreach(), which finds all Users for the
> returned Comments of $this->Post->find().
> ...this makes my CakeApp a little bit slow! Any ideas for a faster
> association?
>
> Many thanks for your answers!
>
> derlippe
> >
>

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