From e66a5c43a8c27711478ad2ddd0b9d23c52645e26 Mon Sep 17 00:00:00 2001 From: Scott Golaszewski Date: Fri, 29 Mar 2013 10:53:16 -0600 Subject: [PATCH 1/3] Adds the unscoped option to active_record models --- README.md | 4 ++++ lib/rails3-jquery-autocomplete/orm/active_record.rb | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 33c33517..aedccd9c 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,10 @@ Only the object's id and the column you are searching on will be returned in JSO Added option to use scopes. Pass scopes in an array. e.g `:scopes => [:scope1, :scope2]` +### :unscoped + Adds the option to unscope the model + e.g. :unscoped => true + #### :column_name By default autocomplete uses method name as column name. Now it can be specified using column_name options `:column_name => 'name'` diff --git a/lib/rails3-jquery-autocomplete/orm/active_record.rb b/lib/rails3-jquery-autocomplete/orm/active_record.rb index 9606c0f2..699ae745 100644 --- a/lib/rails3-jquery-autocomplete/orm/active_record.rb +++ b/lib/rails3-jquery-autocomplete/orm/active_record.rb @@ -18,8 +18,7 @@ def get_autocomplete_items(parameters) limit = get_autocomplete_limit(options) order = get_autocomplete_order(method, options, model) - - items = model.scoped + items = (parameters[:unscoped]) ? model.unscoped : model.scoped scopes.each { |scope| items = items.send(scope) } unless scopes.empty? From ee63b7dcf71bc890e330859883c9f5e90d1235af Mon Sep 17 00:00:00 2001 From: Scott Golaszewski Date: Fri, 29 Mar 2013 11:59:55 -0600 Subject: [PATCH 2/3] Use options instead of parameters. --- lib/rails3-jquery-autocomplete/orm/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rails3-jquery-autocomplete/orm/active_record.rb b/lib/rails3-jquery-autocomplete/orm/active_record.rb index 699ae745..9a9b13d6 100644 --- a/lib/rails3-jquery-autocomplete/orm/active_record.rb +++ b/lib/rails3-jquery-autocomplete/orm/active_record.rb @@ -18,7 +18,7 @@ def get_autocomplete_items(parameters) limit = get_autocomplete_limit(options) order = get_autocomplete_order(method, options, model) - items = (parameters[:unscoped]) ? model.unscoped : model.scoped + items = (options[:unscoped]) ? model.unscoped : model.scoped scopes.each { |scope| items = items.send(scope) } unless scopes.empty? From 9e17de190e7543cfe77f560dc8a143d3f640479f Mon Sep 17 00:00:00 2001 From: Scott Golaszewski Date: Fri, 29 Mar 2013 12:07:41 -0600 Subject: [PATCH 3/3] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aedccd9c..06997df4 100644 --- a/README.md +++ b/README.md @@ -165,8 +165,8 @@ Only the object's id and the column you are searching on will be returned in JSO e.g `:scopes => [:scope1, :scope2]` ### :unscoped - Adds the option to unscope the model - e.g. :unscoped => true + Added the option to unscope the model + e.g. `:unscoped => true` #### :column_name By default autocomplete uses method name as column name. Now it can be specified using column_name options