-
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
Fix #45 Make scopes option can accepts Proc #48
base: master
Are you sure you want to change the base?
Conversation
Scopes can also override the select and where. So you can use code like following to query unique result. autocomplete :item, :brand, full: true, scopes: [-> { unscope(:select).select('MIN(id) as id, brand').group(:brand) }]
end | ||
base + ( options[:extra_data] || [] ) |
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.
Space inside parentheses detected.
I hate @houndci 😆 |
items = items.select(get_autocomplete_select_clause(model, method, options)) unless options[:full_model] | ||
items = items.where(get_autocomplete_where_clause(model, term, method, options)). | ||
limit(limit).order(order) | ||
items = items.where(where) unless where.blank? | ||
|
||
if options[:unique] | ||
scopes << -> { |
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.
Avoid using {...}
for multi-line blocks.
Use the lambda
method for multi-line lambdas.
af87021
to
1bfc32b
Compare
Use unique option to remove dulidate result: autocomplete :item, :brand, full: true, unique: true
items = items.select(get_autocomplete_select_clause(model, method, options)) unless options[:full_model] | ||
items = items.where(get_autocomplete_where_clause(model, term, method, options)). | ||
limit(limit).order(order) | ||
items = items.where(where) unless where.blank? | ||
|
||
if options[:unique] | ||
scopes << lambda do | ||
select = "MIN(#{model.primary_key}) as #{model.primary_key}, #{method}" |
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.
Line is too long. [83/80]
Any news? |
Scopes can also override the select and where.
So you can use code like following to query unique result.