mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
Parenthesize :conditions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*1.12.1*
|
||||
|
||||
* Always parenthesize :conditions options so they may be safely combined with STI and constraints.
|
||||
|
||||
* Correct PostgreSQL primary key sequence detection. #2507 [tmornini@infomania.com]
|
||||
|
||||
* Added support for using limits in eager loads that involve has_many and has_and_belongs_to_many associations
|
||||
|
||||
@@ -296,8 +296,8 @@ module ActiveRecord
|
||||
options.assert_valid_keys(
|
||||
:foreign_key, :class_name, :exclusively_dependent, :dependent,
|
||||
:conditions, :order, :finder_sql, :counter_sql,
|
||||
:before_add, :after_add, :before_remove, :after_remove
|
||||
)
|
||||
:before_add, :after_add, :before_remove, :after_remove
|
||||
)
|
||||
|
||||
association_name, association_class_name, association_class_primary_key_name =
|
||||
associate_identification(association_id, options[:class_name], options[:foreign_key])
|
||||
|
||||
@@ -41,7 +41,7 @@ module ActiveRecord
|
||||
else
|
||||
conditions = "#{@finder_sql}"
|
||||
if sanitized_conditions = sanitize_sql(options[:conditions])
|
||||
conditions << " AND #{sanitized_conditions}"
|
||||
conditions << " AND (#{sanitized_conditions})"
|
||||
end
|
||||
options[:conditions] = conditions
|
||||
options[:joins] = @join_sql
|
||||
@@ -141,7 +141,7 @@ module ActiveRecord
|
||||
@finder_sql = @options[:finder_sql]
|
||||
else
|
||||
@finder_sql = "#{@join_table}.#{@association_class_primary_key_name} = #{@owner.quoted_id} "
|
||||
@finder_sql << " AND #{interpolate_sql(@options[:conditions])}" if @options[:conditions]
|
||||
@finder_sql << " AND (#{interpolate_sql(@options[:conditions])})" if @options[:conditions]
|
||||
end
|
||||
|
||||
@join_sql = "LEFT JOIN #{@join_table} ON #{@association_class.table_name}.#{@association_class.primary_key} = #{@join_table}.#{@association_foreign_key}"
|
||||
|
||||
@@ -26,7 +26,7 @@ module ActiveRecord
|
||||
records = @association_class.find_by_sql(@finder_sql)
|
||||
else
|
||||
sql = @finder_sql
|
||||
sql += " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
|
||||
sql += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions
|
||||
orderings ||= @options[:order]
|
||||
records = @association_class.find_all(sql, orderings, limit, joins)
|
||||
end
|
||||
@@ -45,7 +45,7 @@ module ActiveRecord
|
||||
@association_class.count_by_sql(@finder_sql)
|
||||
else
|
||||
sql = @finder_sql
|
||||
sql += " AND #{sanitize_sql(runtime_conditions)}" if runtime_conditions
|
||||
sql += " AND (#{sanitize_sql(runtime_conditions)})" if runtime_conditions
|
||||
@association_class.count(sql)
|
||||
end
|
||||
end
|
||||
@@ -137,7 +137,7 @@ module ActiveRecord
|
||||
@finder_sql = interpolate_sql(@options[:finder_sql])
|
||||
else
|
||||
@finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}"
|
||||
@finder_sql << " AND #{interpolate_sql(@conditions)}" if @conditions
|
||||
@finder_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions
|
||||
end
|
||||
|
||||
if @options[:counter_sql]
|
||||
@@ -147,7 +147,7 @@ module ActiveRecord
|
||||
@counter_sql = interpolate_sql(@options[:counter_sql])
|
||||
else
|
||||
@counter_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}"
|
||||
@counter_sql << " AND #{interpolate_sql(@conditions)}" if @conditions
|
||||
@counter_sql << " AND (#{interpolate_sql(@conditions)})" if @conditions
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,6 +66,8 @@ module ActiveRecord
|
||||
|
||||
def construct_sql
|
||||
@finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}#{@options[:conditions] ? " AND " + @options[:conditions] : ""}"
|
||||
@finder_sql << " AND (#{sanitize_sql(@options[:conditions])})" if @options[:conditions]
|
||||
@finder_sql
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -893,8 +893,8 @@ module ActiveRecord #:nodoc:
|
||||
condition_segments = [scope_constraints[:conditions]]
|
||||
condition_segments << sanitize_sql(conditions) unless conditions.nil?
|
||||
condition_segments << type_condition unless descends_from_active_record?
|
||||
condition_segments.compact!
|
||||
sql << "WHERE #{condition_segments.join(" AND ")} " unless condition_segments.empty?
|
||||
condition_segments.compact!
|
||||
sql << "WHERE (#{condition_segments.join(") AND (")}) " unless condition_segments.empty?
|
||||
end
|
||||
|
||||
def type_condition
|
||||
|
||||
@@ -168,8 +168,12 @@ class FixturesTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if Account.connection.respond_to?(:reset_pk_sequence!)
|
||||
class FixturesResetPkSequenceTest < Test::Unit::TestCase
|
||||
fixtures :accounts
|
||||
|
||||
if Account.connection.respond_to?(:reset_pk_sequence!)
|
||||
def test_resets_to_min_pk
|
||||
Account.delete_all
|
||||
Account.connection.reset_pk_sequence!(Account.table_name)
|
||||
@@ -284,11 +288,4 @@ class ForeignKeyFixturesTest < Test::Unit::TestCase
|
||||
def test_number2
|
||||
assert true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user