Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:50:21+00:00 2026-05-25T09:50:21+00:00

I am creating a forum for my school. A student will be able to

  • 0

I am creating a forum for my school. A student will be able to create many topics in a particular forum and other students are able to comment on it. The tricky part is that i have a feature where a student can have sub comment to a comment. Lemme tell you my simple table structure which i am using Mysql and developing in cakephp. Below is not the full structure.

User (id,name)
Forums(id,desc,date)
Topics(id,user_id,forum_id,title,content,date)
comments(id,user_id,topics_id,content,date,parent_id) *=> the parent_id referers where the subcomment belongs to.*

I used the cakePHP containable to get all toics and comments of a particular forum in my forum_controller:

$this->find('all',array(
            'contain'=>array(
                'User'=>array(
                    'fields' => array       ('id','displayName','gender','email','profileImgBig')
                 ),'Post'=>array(
                     'User'=>array(
                         'fields' => array('id','displayName','gender','email','profileImgBig')
                     ),
                     'order' => array('Post.created'=>'DESC'),
                 )
            ),
            'conditions'=>array('Topic.forum_id'=>$id),
            'order' => array('Topic.datePosted'=>'DESC')
       ));       

The above retrieves all forum->Topics->User & Topics->Comments->User.

How can i implement in a way that its retrieves all Comments and sub comments? Please help and advice me. Thank you! I am looking at tree behaviour but i am not sure how am i suppose to incorporate with my above find statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:50:21+00:00Added an answer on May 25, 2026 at 9:50 am

    You can indeed use the TreeBehaviour in CakePHP for this. You’ll need to add two more fields to your database (lft, rght) besides parent_id for this and activate it in the model for comments.

    See the CakePHP manual for details, but after activating the behaviour you can use functions like Model::children() and Model::find(‘threaded’) to find all comments that reside below a certain comment (e.g, that are subcomments).

    I would usually first query the database for all topics, and then queue the Comment model for comments and subcomments using the Model::children() function. I wonder though, why would you want to load all topics and all comments within those topics, and not just 1 topic with comments?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Rails application I have a Forum with many Topics. From the Forum's,
I'm creating a forum where user can ask questions and comment on it ....using
I tried to search forum topics to find a tutorial that will guide me
I'm creating a forum website, where each registered user can write many posts and
I'm creating custom forum software for a site I'm building, which includes 2 tables
I'm creating a small forum. Attempting to run SElECT... JOIN... query too pick up
I'm creating a basic forum where every message contains the authors name, some text
I am creating a very simple forum as my first MVC project. My database
I am creating some tag functionality for a forum using linq2sql, and I have
I am creating a form in HTML that will be printed, with fields that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.