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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:38:56+00:00 2026-05-25T00:38:56+00:00

I have a Blog model that has defined var $hasMany=array(Comment); How can i apply

  • 0

I have a Blog model that has defined var $hasMany=array(“Comment”);

How can i apply a filter on the Comments to select only the Blog items that match a certain Comment category?

If, in the Blog model, i do

$this->recursive=2;
$this->hasMany=array("Comment");  //in Comment i have $belongsTo("Blog")
return $this->find("all",array("conditions"=>array("Comment.comment_type_id"=>123)));

i get an error that says Unknown Comment.comment_type_id column because Cake does not make the join.

I think this is a rather common issue so i believe simple to solve but i can’t find a good way

  • 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-25T00:38:57+00:00Added an answer on May 25, 2026 at 12:38 am

    You could work in reverse and select all comments in a particular category and include the blog posts that they were posted to. I can’t find it at the moment, but I’m pretty sure I’ve seen that in the docs as the “recommended” approach and it might be perfectly sufficient in this relatively simple case. It’s definitely what I’d try first.

    You could also use the containable behavior and set a condition on including the Comment, but that will return all blog posts and and no comments where the comment category doesn’t match what you’re after. I’ve never liked this solution because it just feels clumsy and inaccurate to me (though it’s technically not).

    If I really want to limit things, I often use ad hoc joins. I like that they keep my results as clean as possible even though it makes for a more verbose find array.

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

Sidebar

Related Questions

I have a blog that has a redirect loop, and I can't understand htaccess
I have a blog model with has many model comments relationship. So my form
I have an app called blog that has a model called Entry. I use
I have a blog that has a sidebar with a partial view in it
I have a model, blog_posts which has a field published_at. I'd like to select
In a Rails 3 blog type of app, I have a polymorphic comments model,
I have an application that manages documents called Notes. Like a blog, Notes can
I have a blog installed in www.foo.com/wp/ and would like all requests that go
I have a blog-like application with stories and categories: class Category(models.Model): ... class Story(models.Model):
In this simplified scenario, I have a model called Post Each post has a

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.