Skip to content

Fix #45 Make scopes option can accepts Proc#48

Open
lingceng wants to merge 2 commits into
risuiowa:masterfrom
lingceng:master
Open

Fix #45 Make scopes option can accepts Proc#48
lingceng wants to merge 2 commits into
risuiowa:masterfrom
lingceng:master

Conversation

@lingceng

@lingceng lingceng commented Feb 5, 2016

Copy link
Copy Markdown

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) }]
(["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data]))
["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"]
end
base + ( options[:extra_data] || [] )

Copy link
Copy Markdown
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

lingceng commented Feb 5, 2016

Copy link
Copy Markdown
Author

I hate @houndci 😆

items = items.where(where) unless where.blank?

if options[:unique]
scopes << -> {

Copy link
Copy Markdown
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

if options[:unique]
scopes << lambda do
select = "MIN(#{model.primary_key}) as #{model.primary_key}, #{method}"

Copy link
Copy Markdown
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
Copy Markdown

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