public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Parenthesize :conditions

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2681 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jeremy (author)
Tue Oct 18 16:52:07 -0700 2005
commit  328ef3feaad4c110a7277e3432e9203c7fbbb9e2
tree    30337b862f5752c5a2f76c123abf28d94140bc4c
parent  311342d8e231f8429e270dce2b1bf4abeb7b4293
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *1.12.1*
0
 
0
+* Always parenthesize :conditions options so they may be safely combined with STI and constraints.
0
+
0
 * Correct PostgreSQL primary key sequence detection. #2507 [tmornini@infomania.com]
0
 
0
 * Added support for using limits in eager loads that involve has_many and has_and_belongs_to_many associations
...
296
297
298
299
300
 
 
301
302
303
...
296
297
298
 
 
299
300
301
302
303
0
@@ -296,8 +296,8 @@
0
         options.assert_valid_keys(
0
           :foreign_key, :class_name, :exclusively_dependent, :dependent,
0
           :conditions, :order, :finder_sql, :counter_sql,
0
- :before_add, :after_add, :before_remove, :after_remove
0
- )
0
+ :before_add, :after_add, :before_remove, :after_remove
0
+ )
0
 
0
         association_name, association_class_name, association_class_primary_key_name =
0
               associate_identification(association_id, options[:class_name], options[:foreign_key])
...
41
42
43
44
 
45
46
47
...
141
142
143
144
 
145
146
147
...
41
42
43
 
44
45
46
47
...
141
142
143
 
144
145
146
147
0
@@ -41,7 +41,7 @@
0
         else
0
           conditions = "#{@finder_sql}"
0
           if sanitized_conditions = sanitize_sql(options[:conditions])
0
- conditions << " AND #{sanitized_conditions}"
0
+ conditions << " AND (#{sanitized_conditions})"
0
           end
0
           options[:conditions] = conditions
0
           options[:joins] = @join_sql
0
@@ -141,7 +141,7 @@
0
             @finder_sql = @options[:finder_sql]
0
           else
0
             @finder_sql = "#{@join_table}.#{@association_class_primary_key_name} = #{@owner.quoted_id} "
0
- @finder_sql << " AND #{interpolate_sql(@options[:conditions])}" if @options[:conditions]
0
+ @finder_sql << " AND (#{interpolate_sql(@options[:conditions])})" if @options[:conditions]
0
           end
0
           
0
           @join_sql = "LEFT JOIN #{@join_table} ON #{@association_class.table_name}.#{@association_class.primary_key} = #{@join_table}.#{@association_foreign_key}"
...
26
27
28
29
 
30
31
32
...
45
46
47
48
 
49
50
51
...
137
138
139
140
 
141
142
143
...
147
148
149
150
 
151
152
153
...
26
27
28
 
29
30
31
32
...
45
46
47
 
48
49
50
51
...
137
138
139
 
140
141
142
143
...
147
148
149
 
150
151
152
153
0
@@ -26,7 +26,7 @@
0
           records = @association_class.find_by_sql(@finder_sql)
0
         else
0
           sql = @finder_sql
0
- sql += " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
0
+ sql += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions
0
           orderings ||= @options[:order]
0
           records = @association_class.find_all(sql, orderings, limit, joins)
0
         end
0
@@ -45,7 +45,7 @@
0
           @association_class.count_by_sql(@finder_sql)
0
         else
0
           sql = @finder_sql
0
- sql += " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
0
+ sql += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions
0
           @association_class.count(sql)
0
         end
0
       end
0
@@ -137,7 +137,7 @@
0
             @finder_sql = interpolate_sql(@options[:finder_sql])
0
           else
0
             @finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}"
0
- @finder_sql << " AND #{interpolate_sql(@conditions)}" if @conditions
0
+ @finder_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions
0
           end
0
 
0
           if @options[:counter_sql]
0
@@ -147,7 +147,7 @@
0
             @counter_sql = interpolate_sql(@options[:counter_sql])
0
           else
0
             @counter_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}"
0
- @counter_sql << " AND #{interpolate_sql(@conditions)}" if @conditions
0
+ @counter_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions
0
           end
0
         end
0
     end
...
66
67
68
 
 
69
70
71
...
66
67
68
69
70
71
72
73
0
@@ -66,6 +66,8 @@
0
 
0
         def construct_sql
0
           @finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}#{@options[:conditions] ? " AND " + @options[:conditions] : ""}"
0
+ @finder_sql << " AND (#{sanitize_sql(@options[:conditions])})" if @options[:conditions]
0
+ @finder_sql
0
         end
0
     end
0
   end
...
893
894
895
896
897
 
 
898
899
900
...
893
894
895
 
 
896
897
898
899
900
0
@@ -893,8 +893,8 @@
0
           condition_segments = [scope_constraints[:conditions]]
0
           condition_segments << sanitize_sql(conditions) unless conditions.nil?
0
           condition_segments << type_condition unless descends_from_active_record?
0
- condition_segments.compact!
0
- sql << "WHERE #{condition_segments.join(" AND ")} " unless condition_segments.empty?
0
+ condition_segments.compact!
0
+ sql << "WHERE (#{condition_segments.join(") AND (")}) " unless condition_segments.empty?
0
         end
0
 
0
         def type_condition
...
168
169
170
 
171
172
 
 
 
 
173
174
175
...
284
285
286
287
288
...
168
169
170
171
172
 
173
174
175
176
177
178
179
...
288
289
290
 
291
0
@@ -168,8 +168,12 @@
0
       end
0
     end
0
   end
0
+end
0
 
0
- if Account.connection.respond_to?(:reset_pk_sequence!)
0
+if Account.connection.respond_to?(:reset_pk_sequence!)
0
+ class FixturesResetPkSequenceTest < Test::Unit::TestCase
0
+ fixtures :accounts
0
+
0
     def test_resets_to_min_pk
0
       Account.delete_all
0
       Account.connection.reset_pk_sequence!(Account.table_name)
0
@@ -284,6 +288,5 @@
0
   def test_number2
0
     assert true
0
   end
0
-
0
 end

Comments

    No one has commented yet.