Allow use of pluck instead of select#47
Open
lastobelus wants to merge 4 commits into
Open
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'}
| 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 } |
Collaborator
There was a problem hiding this comment.
Prefer Object#is_a? over Object#kind_of?.
Space missing to the left of {.
Collaborator
|
@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| |
Collaborator
There was a problem hiding this comment.
Prefer map over collect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.