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
search only specific attributes in association queries #136
Comments
Tried something like this: ransacker :member_first_name do |parent|
# joins(:member).select('members.first_name')
Arel::Nodes::SqlLiteral.new(joins(:member).select('members.first_name').first)
# Arel::Nodes::SqlLiteral.new(
# Arel::SelectManager.join("genes.member_id = members.id",:members)
# )
end with no luck... getting this error: Need help... :( |
This works fine when using simple search: def self.member_member_name
:member_first_name_or_member_last_name_cont
end But I need it to be added to the advanced search select options, so I'm guessing the only way to do this is by adding a ransacker. (no luck in that end....) |
You can restrict the attributes available for searching by overriding the class method def self.ransackable_attributes(auth_object = nil)
# super - %w( created_at updated_at parent_id )
%w( name email ) + _ransackers.keys
end |
And if I need to search by association attribute? For example:
And I would like my user to be able to do advance search by the catalog number of this antibody. If I change my simple search field to be What am I missing...? |
Any update on this? Also interested in this functionality. |
+1 |
@alkalinecoffee You can be sure that if there was an update on this it would be posted in this thread. All the information in this thread is all the information about this problem. |
@lironbeni Is defining |
The way I solved my problem with searching by association fields (purchasable in Antibody for example) is to add them to my columns_to_include_in_search of Antibody this way: ...{:label => :purchasable_catalog_number, :type => :string},
{:label => :purchasable_company_id, :type => :purchasableSelect },
{:label => :purchasable_price, :type => :integer} .... Please note that it's important to set the label as a symbol and not as a string, because this way ransack "understands" this is an association field. Regarding the full name search, I'm still struggling.. And now I need to be able to do sorting by association field, that I still not sure how it can be done (will update if I'll manage to do so) |
@lironbeni thanks for the tip on the symbol vs string. That was the missing piece for me. |
Closed |
Hi Ernie,
How can I restrict the attributes of associated module in association query.
Say I have this in my condition_fields.html.erb file:
<%= a.attribute_select :associations => [:member] %>
It will show in the select box about 24 member fields, while I would like to show only the name and the email of the member.
How to that?
Thanks,
Liron
The text was updated successfully, but these errors were encountered: