Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Get post with 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
  2 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
 
Max Power  
View profile  
 More options Jan 9, 5:34 am
From: Max Power <laran.ta...@gmail.com>
Date: Wed, 9 Jan 2013 02:34:25 -0800 (PST)
Local: Wed, Jan 9 2013 5:34 am
Subject: Get post with comments

Hi,

I want to paginate over posts which has some comments. That is, I want to
get from the database only those posts which has al least one comments and,
for each post, all the associated comments:

$post => array(
    [0] => array(
        Post,
        Comments => array(
            [0] => comment,
            ....
         )
   )
)

How can I do that?

I have got posts with some comments joining posts and commets tables, but I
don't know how to get all comments for each post.

$this->paginate['joins'] = array(
                    'table' => 'comments',
                    'alias' => 'Comment',
                    'type' => 'RIGHT',
                    'conditions' => array('Comment.post_id  = Post.id');
                );
$this->paginate['group'] = array('Post.id');
$posts = $personas = $this->paginate(null);

Kind regards,


 
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.
lowpass  
View profile  
 More options Jan 9, 2:09 pm
From: lowpass <zijn.digi...@gmail.com>
Date: Wed, 9 Jan 2013 14:09:16 -0500
Local: Wed, Jan 9 2013 2:09 pm
Subject: Re: Get post with comments

On Wed, Jan 9, 2013 at 5:34 AM, Max Power <laran.ta...@gmail.com> wrote:
> Hi,

> I want to paginate over posts which has some comments. That is, I want to
> get from the database only those posts which has al least one comments and,
> for each post, all the associated comments:

The simplest way to handle this is to use counterCache. Add a column,
comment_count, to your posts table. In the Comment model ...

public $belongsTo = array(
        'Post' => array(
                'className' => 'Post',
                'foreignKey' => 'post_id',
                'counterCache' => 'comment_count'
        )
        //...
);

Whenever a new Comment is added the comment_count value will be incremented.

public $paginate = array(
        'fields' => ...,
        'limit' => ...,
        'order'=> ...,
        'conditions' => array(
                'Post.comment_count >' => 0
        ),
        'contain' => array('Comment')
);


 
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 »