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

  • Home
  • SEARCH
  • 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 6664605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:37:46+00:00 2026-05-26T02:37:46+00:00

I have a product model, a category model, and a product_categorization model (has_many…, through

  • 0

I have a product model, a category model, and a product_categorization model (has_many…, through association). I am using the meta_search gem to conduct product searches. For some reason, even though my log is pulling the correct criterias, it is not filtering the products based on the category. No matter what I choose, it always displays all the products.

Product controller:

def update
params[:product][:category_ids] ||= []
@product = Product.find(params[:id])
if @product.update_attributes(params[:product])
 redirect_to @product
else
 render "edit"
end 

product search form:

  <div class="field">
   <%= f.label :category %>
   <%= f.collection_select :product_categorizations_category_id_equals_any, Category.all, :id, :name, :include_blank => true, :prompt => "Select a category" %> 
  </div>   

Any help would be appreciated. Also, is there a better gem out there that I can use? I know searchlogic is not rails 3 compatible unless you get the patch. Is the patched version of searchlogic a better option than meta_search? Thanks.

UPDATE: RESOLVED:

Sooo after many hours of mulling this over, I figured it out. I am not sure this is the explanation, but after *deleting the “any” from “:product_categorizations_category_id_equals_any”*, I got it to work. I think the reason is because this is a has_many through association, the category_id is not stored as an array so the “any” was not relevant. My explanation may be completely off, but it works.

  • 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-26T02:37:46+00:00Added an answer on May 26, 2026 at 2:37 am

    meta_search should be working fine for has_many through associations (but also habtm) e.g. I have a user has many teams model where:

    class User < ActiveRecord::Base
      has_many :users_teams, :class_name => 'UsersTeams', :dependent => :destroy
      has_many :teams, :through => :users_teams
    end
    

    All of the following all return correctly filtered results:

    User.search :teams_id_equals=>999
    User.search :users_teams_team_id_equals=>999
    User.search :teams_id_equals_any=>[999]
    User.search :users_teams_team_id_equals_any=>[999]
    

    I suspect your problem may not be meta_search itself, but some other cause (like the form parameters not being correctly received and passed to search, or the associations not defined correctly).

    Suggest that you first verify the search at the model level (either in the console with queries like the ones above; but ideally have a test in your project for this). Next would be to ensure that the parameters are being correctly received and passed to search.

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

Sidebar

Related Questions

I have Product model and it has many categories with a has_many :through association
I have two model Product and Category, they have has_many, and belongs_to association respectively.
I have a Category, a Subcategory and a Product model. I have: Category has_many
I have a Model called Category and other Model Product. They have has_many and
i have a product model and a product category model. and theres a habtm
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
Let's say I have this model named Product with a field named brand .
Let's assume I have a model called product. Let's assume that product has three
Here is the problem. lets say I have a product category table and a
I have the following models: class Indicator(models.Model): name = models.CharField(max_length=200) category = models.ForeignKey(IndicatorCategory) weight

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.