Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lingceng
Copy link

@lingceng lingceng commented Feb 5, 2016

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) }]

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] || [] )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside parentheses detected.

@lingceng
Copy link
Author

lingceng commented Feb 5, 2016

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 << -> {
Copy link
Collaborator

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.

@lingceng lingceng force-pushed the master branch 2 times, most recently from af87021 to 1bfc32b Compare February 5, 2016 07:47
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}"
Copy link
Collaborator

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]

@bigtunacan bigtunacan added this to the 1.0.5 milestone Feb 26, 2016
@dgilperez
Copy link

Any news?

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

Successfully merging this pull request may close these issues.

4 participants