Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Lots of queries to pull up user photos and their comments
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
centr0  
View profile  
 More options Nov 4, 4:44 am
From: centr0 <centrosc...@gmail.com>
Date: Tue, 3 Nov 2009 09:44:09 -0800 (PST)
Local: Wed, Nov 4 2009 4:44 am
Subject: Lots of queries to pull up user photos and their comments
my models:

user hasmany comment
profile hasmany comment
user hasone profile
user hasone photo

comment belongsto user
profile belongsto user
photo belongsto user

what im trying to do is pull up profile information and the profiles
comments.

here is my index() and its find():
        function index($url = null) {
                $this->Profile->recursive = -1;

                /*
                *
                */
                $profile = $this->Profile->find('first', array(
                        'conditions' => array('Profile.url' => $url),
                        'contain' => array(
                                'User' => array(
                                        'fields' => array(
                                                'User.id','User.name'
                                        ),
                                        'Photo' => array(
                                                'fields' => array(
                                                        'Photo.thumbnail','Photo.image'
                                                )
                                        )
                                ),
                                'Comment' => array(
                    'User' => array(
                        'fields' => array(
                            'User.name'
                        ),
                        'Photo' => array(
                            'fields' => array(
                                'Photo.thumbnail'
                            )
                        )
                    )
                )
                        )
                ));
                $this->set('profile', $profile);
        }

this function takes its function arg and finds the appropriate profile
ie. /profiles/index/centroscape

Everything returns correctly without error i get exactly what i want,
but once the query gets to the Photo part, it queries multiple times
for photos with different ids.  if there is a way to avoid 1 query per
photo please let me know.  I dont think there is.

imagine a profile with 50-80 comments.  its kind of scary.  also, this
is my first time implementing containable behavior. any tips other
than my question are welcome!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
centr0  
View profile  
 More options Nov 5, 5:07 am
From: centr0 <centrosc...@gmail.com>
Date: Wed, 4 Nov 2009 10:07:12 -0800 (PST)
Local: Thurs, Nov 5 2009 5:07 am
Subject: Re: Lots of queries to pull up user photos and their comments
Update:

This query is what i typically want run for the comments part of the
contain:

SELECT Comment.content, Comment.created, Comment.modified,
Photo.thumbnail, User.name
                                                                FROM comments AS Comment
                                                                LEFT JOIN profiles AS i ON Comment.profile_id = i.id
                                                                LEFT JOIN users AS User ON Comment.user_id = User.id
                                                                LEFT JOIN photos AS Photo ON User.id = Photo.user_id
                                                                WHERE Comment.profile_id =1

anyway to portray this the cake way?  id like to stay away from custom
SQL.  Thanks.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Miles J  
View profile  
 More options Nov 5, 6:44 am
From: Miles J <mileswjohn...@gmail.com>
Date: Wed, 4 Nov 2009 11:44:45 -0800 (PST)
Local: Thurs, Nov 5 2009 6:44 am
Subject: Re: Lots of queries to pull up user photos and their comments
Use the "join" parameter within find. However, theres not really any
documentation on it, so you would have to read the source code
manually.

On Nov 4, 10:07 am, centr0 <centrosc...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dr. Loboto  
View profile  
 More options Nov 5, 1:37 pm
From: "Dr. Loboto" <drlob...@gmail.com>
Date: Wed, 4 Nov 2009 18:37:08 -0800 (PST)
Local: Thurs, Nov 5 2009 1:37 pm
Subject: Re: Lots of queries to pull up user photos and their comments
But there is very helpful article:
http://bakery.cakephp.org/articles/view/quick-tip-doing-ad-hoc-joins-...

On Nov 5, 1:44 am, Miles J <mileswjohn...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google