Skip to content
New issue

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

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

Already on GitHub? # to your account

Is it possible to add filter on an HABTM associated model's field ? #1342

Closed
Val opened this issue Oct 1, 2012 · 8 comments
Closed

Is it possible to add filter on an HABTM associated model's field ? #1342

Val opened this issue Oct 1, 2012 · 8 comments

Comments

@Val
Copy link

Val commented Oct 1, 2012

I'm trying to override list view pretty_value on associated model to provide a quick link to associated model's list using filter to show only associated records.

It works well for has_many associations but not for HABTM ones.

To see it try this gist : https://gist.github.com/3810559

Author 1-N Book works
Book N-N Collection doesn't : if you try to add a book filter in collection list or a collection filter in book list there is no selector option ("contains", "is exactly", etc.)

Any tips or documentation pointer ?
Regards.

@bbenezech
Copy link
Collaborator

No, it's not possible at the moment.
Only belongs_to, sorry.

@Val
Copy link
Author

Val commented Oct 2, 2012

Ok, thanks.

May be I could help you providing this feature.
Is it a client-side problem, a server side one or the both ? Do you have any plan for it or any pointer in sources ?

Regards.

@Val
Copy link
Author

Val commented Oct 2, 2012

Could you try this hack : https://github.com/Val/rails_admin/commit/6cc8ac5d3f8ea0bf1eae1145f27851fccc50911b

It's working for me but I'm not sure to follow your code style... Hope it helps.

@Val
Copy link
Author

Val commented Oct 4, 2012

Note: lines 42-44 of ra.filter-box.js were ended with a non-printable space character and I did remove them, that's why they appear on diff.

@Val
Copy link
Author

Val commented Oct 8, 2012

@mshibuya
Copy link
Member

Your work looks nice, but some more jobs still need to be done.

  1. It comes with no tests.
  2. Forcing include of has_and_belongs_to_many association may produce massive amount of DB access. Instead of it, we'll need some kind of a configuration option to control eager-loading of has_many/has_and_belongs_to_many association.

How's your opinion on them?

@Val
Copy link
Author

Val commented Oct 25, 2012

@mshibuya : Thanks for taking time to review the patch.

I agree with you, it needs tests and lacks some kind of configuration option and perhaps a better rails_admin DSL inclusion too.

I'll try to refactor my code.

@barsukov
Copy link

I need same functionality for has_many :thorugh association may be it is possible to implement it too ? and i did not find any filter code for simple has_many association (without through) , I can try to implement it I think you code can help me. :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants