searchlogic 2.1.10 → 2.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION.yml +1 -1
- data/lib/searchlogic/named_scopes/association_conditions.rb +15 -4
- data/lib/searchlogic/named_scopes/conditions.rb +2 -2
- data/searchlogic.gemspec +1 -1
- data/spec/named_scopes/association_conditions_spec.rb +4 -0
- data/spec/search_spec.rb +6 -0
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 2.1.11 released 2009-07-28
|
2
|
+
|
3
|
+
* Reworked how alias conditions are created on the fly, uses scope(:find) instead of proxy_options to create the scope. This allows using association alias named scopes.
|
4
|
+
|
1
5
|
== 2.1.10 released 2009-07-28
|
2
6
|
|
3
7
|
* Ignore polymorphic associations when dynamically creating conditions on associations.
|
data/VERSION.yml
CHANGED
@@ -52,7 +52,13 @@ module Searchlogic
|
|
52
52
|
assocs = non_polymorphic_associations
|
53
53
|
return nil if assocs.empty?
|
54
54
|
regexes = [association_searchlogic_regex(assocs, Conditions::PRIMARY_CONDITIONS)]
|
55
|
-
assocs.each
|
55
|
+
assocs.each do |assoc|
|
56
|
+
scope_names = assoc.klass.scopes.keys + assoc.klass.alias_scopes.keys
|
57
|
+
scope_names.uniq!
|
58
|
+
scope_names.delete(:scoped)
|
59
|
+
next if scope_names.empty?
|
60
|
+
regexes << /^(#{assoc.name})_(#{scope_names.join("|")})$/
|
61
|
+
end
|
56
62
|
|
57
63
|
if !local_condition?(name) && regexes.any? { |regex| name.to_s =~ regex }
|
58
64
|
{:association => $1, :column => $2, :condition => $3}
|
@@ -66,7 +72,10 @@ module Searchlogic
|
|
66
72
|
end
|
67
73
|
|
68
74
|
def association_alias_condition_details(name)
|
69
|
-
|
75
|
+
assocs = non_polymorphic_associations
|
76
|
+
return nil if assocs.empty?
|
77
|
+
|
78
|
+
if !local_condition?(name) && name.to_s =~ association_searchlogic_regex(assocs, Conditions::ALIAS_CONDITIONS)
|
70
79
|
{:association => $1, :column => $2, :condition => $3}
|
71
80
|
end
|
72
81
|
end
|
@@ -96,7 +105,8 @@ module Searchlogic
|
|
96
105
|
if !arity || arity == 0
|
97
106
|
# The underlying condition doesn't require any parameters, so let's just create a simple
|
98
107
|
# named scope that is based on a hash.
|
99
|
-
options = scope.
|
108
|
+
options = scope.scope(:find)
|
109
|
+
options.delete(:readonly)
|
100
110
|
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
|
101
111
|
options
|
102
112
|
else
|
@@ -121,7 +131,8 @@ module Searchlogic
|
|
121
131
|
|
122
132
|
eval <<-"end_eval"
|
123
133
|
searchlogic_lambda(:#{arg_type}) { |#{proc_args.join(",")}|
|
124
|
-
options = association.klass.
|
134
|
+
options = association.klass.send(association_condition, #{proc_args.join(",")}).scope(:find)
|
135
|
+
options.delete(:readonly)
|
125
136
|
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
|
126
137
|
options
|
127
138
|
}
|
@@ -140,8 +140,8 @@ module Searchlogic
|
|
140
140
|
|
141
141
|
def create_primary_condition(column, condition)
|
142
142
|
column_type = columns_hash[column.to_s].type
|
143
|
-
match_keyword =
|
144
|
-
|
143
|
+
match_keyword = ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
144
|
+
|
145
145
|
scope_options = case condition.to_s
|
146
146
|
when /^equals/
|
147
147
|
scope_options(condition, column_type, "#{table_name}.#{column} = ?")
|
data/searchlogic.gemspec
CHANGED
@@ -13,6 +13,10 @@ describe "Association Conditions" do
|
|
13
13
|
Company.users_uname("bjohnson").proxy_options.should == User.uname("bjohnson").proxy_options.merge(:joins => :users)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should allow the use of foreign pre-existing alias scopes" do
|
17
|
+
Company.users_username_has("bjohnson").proxy_options.should == User.username_has("bjohnson").proxy_options.merge(:joins => :users)
|
18
|
+
end
|
19
|
+
|
16
20
|
it "should ignore polymorphic associations" do
|
17
21
|
lambda { Fee.owner_created_at_gt(Time.now) }.should raise_error(NoMethodError)
|
18
22
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -109,6 +109,12 @@ describe "Search" do
|
|
109
109
|
search.orders_total_gt.should == 10
|
110
110
|
end
|
111
111
|
|
112
|
+
it "should allow setting pre-existing association conditions" do
|
113
|
+
search = Company.search
|
114
|
+
search.users_uname = "bjohnson"
|
115
|
+
search.users_uname.should == "bjohnson"
|
116
|
+
end
|
117
|
+
|
112
118
|
it "should allow using custom conditions" do
|
113
119
|
User.named_scope(:four_year_olds, { :conditions => { :age => 4 } })
|
114
120
|
search = User.search
|