-
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
Search by several fields #86
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,24 @@ def active_record_get_autocomplete_items(parameters) | |
scopes = Array(options[:scopes]) | ||
where = options[:where] | ||
limit = get_autocomplete_limit(options) | ||
order = active_record_get_autocomplete_order(method, options, model) | ||
order = Array.new | ||
|
||
items = (::Rails::VERSION::MAJOR * 10 + ::Rails::VERSION::MINOR) >= 40 ? model.where(nil) : model.scoped | ||
|
||
scopes.each { |scope| items = items.send(scope) } unless scopes.empty? | ||
|
||
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) | ||
|
||
clauses = [] | ||
conditions = [] | ||
param_to_array(method).each do |method| | ||
c = get_autocomplete_where_clause(model, term, method, options) | ||
clauses << c[0] | ||
conditions << c[1] | ||
order << active_record_get_autocomplete_order(method, options, model) | ||
end | ||
|
||
items = items.where(clauses.join(' OR '), *conditions).limit(limit).order(order.join(', ')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
items = items.where(where) unless where.blank? | ||
|
||
items | ||
|
@@ -43,7 +52,11 @@ def get_autocomplete_select_clause(model, method, options) | |
] + (options[:extra_data].blank? ? [] : options[:extra_data])) | ||
else | ||
table_name = model.table_name | ||
(["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data])) | ||
l = ["#{table_name}.#{model.primary_key}"] | ||
param_to_array(method).each do |method| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shadowing outer local variable - method. |
||
l << "#{table_name}.#{method}" | ||
end | ||
(l + (options[:extra_data].blank? ? [] : options[:extra_data])) | ||
end | ||
end | ||
|
||
|
@@ -78,6 +91,11 @@ def postgres?(model) | |
# Figure out if this particular model uses the PostgreSQL adapter | ||
model.connection.class.to_s.match(/PostgreSQLAdapter/) | ||
end | ||
|
||
def param_to_array(s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
return s if s.kind_of?(Array) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer Object#is_a? over Object#kind_of?. |
||
return [s] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
end | ||
end |
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.
Shadowing outer local variable - method.