-
Notifications
You must be signed in to change notification settings - Fork 80
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
Allow use of pluck instead of select #47
base: master
Are you sure you want to change the base?
Allow use of pluck instead of select #47
Conversation
this in conjunction with using a scope that joins an association allows fetching attributes of associated records. class Organization belongs_to :contact scope :with_contact, -> { joins(:contact) } end autocomplete :organization, :name, extra_data: ['contacts.email'], select_method: :pluck, scopes: [:with_contact] f.autocomplete_field :name, autocomplete_organization_name_product_path, update_elements: {id: '#products_organization_attributes_id', 'contacts.email': '#products_contact_attributes_email'}
@@ -77,6 +79,7 @@ class AutocompleteTest < Test::Unit::TestCase | |||
should 'add that extra data to result' do | |||
item = mock(Object) | |||
mock(item).send(:name).times(2) { 'Object Name' } | |||
stub(item).kind_of?(Hash){ false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer Object#is_a?
over Object#kind_of?
.
Space missing to the left of {.
@lastobelus Yeah; this looks useful. If you want to add a couple of test cases and some documentation to the readme I'll merge it in. Thanks |
because rails internally does a uniq before querying
item["label"] = item["value"] = item[method.to_s] | ||
end | ||
else | ||
items = items.collect do |item| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer map
over collect
.
this in conjunction with using a scope that joins
an association allows fetching attributes of associated
records.
I have not yet written any tests, let me know if you are interested in including this and I will try to provide some coverage.