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 8626787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:07:00+00:00 2026-06-12T08:07:00+00:00

I have two model name image and comment. here the relation is like image

  • 0

I have two model name image and comment. here the relation is like image has many comments . Now in my listing page I want to display all imae detail and only the no of comment on that image . can you tell me how should I get that ?
after I write the query my return data is

Array
(

    [0] => Array
        (
            [Image] => Array
                (
                    [image_id] => 57
                    [user_id] => 1
                    [category_id] => 22
                    [image_title] => scroul
                    [description] => beutifull natural image for the animal
                    [keyword] => scrual
                    [image_price] => 
                    [image_name] => 7bf4a72509da5906903c84e88228b9dd.jpg
                    [image_path] => img/uploads/images/original/
                    [image_available_size] => 
                    [like] => 12
                    [size] => 3244
                    [resolution] => 2162 x 1644
                    [i_date] => 1348573022
                    [i_by] => 1
                    [u_date] => 1348573022
                    [u_by] => 1
                    [is_active] => Y
                    [is_deleted] => N
                )

            [Comment] => Array
                (
                    [0] => Array
                        (
                            [comment_id] => 5
                            [image_id] => 57
                            [user_id] => 2
                            [comment] => socute
                            [comment_date] => 1348739230
                            [is_active] => N
                            [is_deleted] => N
                        )

                )

        )

    [1] => Array
        (
            [Image] => Array
                (
                    [image_id] => 56
                    [user_id] => 1
                    [category_id] => 22
                    [image_title] => cute dog
                    [description] => cute dog looking 
                    [keyword] => 
                    [image_price] => 
                    [image_name] => d4af899b0d52cccbec94952a3abd0077.jpg
                    [image_path] => img/uploads/images/original/
                    [image_available_size] => 
                    [like] => 8
                    [size] => 620
                    [resolution] => 2592 x 1944
                    [i_date] => 1348572897
                    [i_by] => 1
                    [u_date] => 1348572897
                    [u_by] => 1
                    [is_active] => Y
                    [is_deleted] => N
                )

            [Comment] => Array
                (
                    [0] => Array
                        (
                            [comment_id] => 3
                            [image_id] => 56
                            [user_id] => 2
                            [comment] => ohhhhhhh
                            [comment_date] => 1348737968
                            [is_active] => N
                            [is_deleted] => N
                        )

                )

        )

    [3] => Array
        (
            [Image] => Array
                (
                    [image_id] => 55
                    [user_id] => 1
                    [category_id] => 22
                    [image_title] => ships
                    [description] => ships with beutiful green background
                    [keyword] => ship,green,animal,nature,background,eating,white ship
                    [image_price] => 
                    [image_name] => c0dfc2432ae047e9160f3ef99880fe87.jpg
                    [image_path] => img/uploads/images/original/
                    [image_available_size] => 
                    [like] => 1
                    [size] => 1831
                    [resolution] => 2520 x 1944
                    [i_date] => 1348572846
                    [i_by] => 1
                    [u_date] => 1348661976
                    [u_by] => 1
                    [is_active] => Y
                    [is_deleted] => N
                )

            [Comment] => Array
                (
                    [0] => Array
                        (
                            [comment_id] => 2
                            [image_id] => 55
                            [user_id] => 2
                            [comment] =>  i like it
                            [comment_date] => 1348737942
                            [is_active] => Y
                            [is_deleted] => N
                        )

                    [1] => Array
                        (
                            [comment_id] => 4
                            [image_id] => 55
                            [user_id] => 2
                            [comment] =>  good scene
                            [comment_date] => 1348738004
                            [is_active] => N
                            [is_deleted] => N
                        )
                )
        )
)

in the above array there is a all comment of that image. I don’t want here comment list I just want no of comments .

  • 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-06-12T08:07:01+00:00Added an answer on June 12, 2026 at 8:07 am

    Could you post the find statement you’re using. You can set recursive to a certain level, from the documentation:

    • -1 Cake fetches Group data only, no joins.
    • 0 Cake fetches Group data and its domain
    • 1 Cake fetches a Group, its domain and its associated Users
    • 2 Cake fetches a Group, its domain, its associated Users, and the Users’ associated Articles

    So you can call the following if you only want the data from the current model only:

    $this->Model->find('all', array('recursive' => -1));
    

    There is also the Containable behavior, which allows you to specify which Model data you want to retrieve when calling find.

    Say you have a Post model which hasMany Image. The call, with the Containable behaviour in the Post Model properly included, would be:

    $this->Post->find('all', array(
     'conditions' => array('Post.id' => 1),
     'contain' => array('Image')
    ));
    

    EDIT:
    Because of the spelling and formatting I misread your initial question. I thought you wanted “no comments” to appear in the data array, instead you want only the “number of comments” to appear.

    If you want the comment count, use counterCache as Kishor Kundan proposes.

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

Sidebar

Related Questions

I have two tables like so: class Collection(models.Model): name = models.CharField() class Image(models.Model): name
I have two model: User, Article A user can like or dislike many articles,
If I have two models like class Author(models.Model): name = models.CharField(max_length=100) title = models.CharField(max_length=3,
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
if I have two simple models: class Tag(models.Model): name = models.CharField(max_length=100) class Post(models.Model): title
I have two models with slug fields: class Book(models.Model): name = models.CharField(max_length=200) slug =
I have two models class Status(models.Model) name = models.CharField(max_length=25) rank = models.PositiveSmallIntegerField() class MyModel(models.Model)

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.