mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Prevent overwriting of table name in merging SQL conditions [#2949 state:resolved]
This commit is contained in:
parent
00d6c76660
commit
0472839d68
3 changed files with 14 additions and 2 deletions
|
@ -2294,10 +2294,12 @@ module ActiveRecord #:nodoc:
|
|||
# And for value objects on a composed_of relationship:
|
||||
# { :address => Address.new("123 abc st.", "chicago") }
|
||||
# # => "address_street='123 abc st.' and address_city='chicago'"
|
||||
def sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name)
|
||||
def sanitize_sql_hash_for_conditions(attrs, default_table_name = quoted_table_name)
|
||||
attrs = expand_hash_conditions_for_aggregates(attrs)
|
||||
|
||||
conditions = attrs.map do |attr, value|
|
||||
table_name = default_table_name
|
||||
|
||||
unless value.is_a?(Hash)
|
||||
attr = attr.to_s
|
||||
|
||||
|
|
|
@ -368,6 +368,12 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_table_names_for_chaining_scopes_with_and_without_table_name_included
|
||||
assert_nothing_raised do
|
||||
Comment.for_first_post.for_first_author.all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class DynamicScopeMatchTest < ActiveRecord::TestCase
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
named_scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
|
||||
|
||||
named_scope :for_first_post, :conditions => { :post_id => 1 }
|
||||
named_scope :for_first_author,
|
||||
:joins => :post,
|
||||
:conditions => { "posts.author_id" => 1 }
|
||||
|
||||
belongs_to :post, :counter_cache => true
|
||||
|
||||
def self.what_are_you
|
||||
|
|
Loading…
Reference in a new issue