Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by HABTM association throws exception #515

Closed
micapam opened this issue Sep 22, 2011 · 10 comments
Closed

Filter by HABTM association throws exception #515

micapam opened this issue Sep 22, 2011 · 10 comments

Comments

@micapam
Copy link

micapam commented Sep 22, 2011

My models Product and Category have a many-to-many relationship via HABTM.

I thought that for products, I could just say:

filter :categories, :as => :check_boxes, :collection => proc { Category.all }

... but this throws an error:

undefined method `category_ids_in' for #MetaSearch::Searches::Product:0x000001079b25c8

How would I get filtering to work for this relationship? I can't specify the bridging table (categories_products) as the source of the collection, because it's a HABTM relationship so there's no such class as CategoryProduct. I don't want to (and shouldn't have to) change my data model.

@akashkamboj
Copy link

+1
I second that. Only alternative I could find is creating scopes for the time being.

@phillyslick
Copy link

filter :categories_id, :as => :check_boxes

stumbled upon it the other day

@micapam
Copy link
Author

micapam commented Nov 22, 2011

That's great - thanks phillyslick.

@thbar
Copy link
Contributor

thbar commented Feb 10, 2012

I get duplicates if I select two categories (although it works!).

Did you guys find a way to dedupe records? (see #982)

@Lordnibbler
Copy link

^ still having this issue. #982 above updated in comments with rly shitty workaround :P

@thbar
Copy link
Contributor

thbar commented Feb 10, 2012

thanks :)

@pcreux
Copy link
Contributor

pcreux commented Feb 23, 2012

@thbar Did this commit fix it? 2ce2f33

@thbar
Copy link
Contributor

thbar commented Feb 24, 2012

@pcreux dunno yet, I will work again on the admin part in a couple of weeks, I'll report back! Thanks for the heads-up!

@Lordnibbler
Copy link

Is this commit merged in master? If so, it did not fix the duplicate results issue for me.

@leonelgalan
Copy link
Contributor

I'm getting the error on 0.4.2 with :as => :select, but not with :as => :check_boxes, it was working before (on 0.4.0, but it stopped working so I updated, but still not working)

@pcreux pcreux closed this as completed May 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants