mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated expand_hash_conditions_for_aggregates
This commit is contained in:
parent
60c8a03c8d
commit
27b252d6a8
3 changed files with 7 additions and 46 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
||||||
|
|
||||||
|
*Rafael Mendonça França*
|
||||||
|
|
||||||
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
||||||
|
|
||||||
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
||||||
|
|
|
@ -134,43 +134,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Accepts a hash of SQL conditions and replaces those attributes
|
|
||||||
# that correspond to a {#composed_of}[rdoc-ref:Aggregations::ClassMethods#composed_of]
|
|
||||||
# relationship with their expanded aggregate attribute values.
|
|
||||||
#
|
|
||||||
# Given:
|
|
||||||
#
|
|
||||||
# class Person < ActiveRecord::Base
|
|
||||||
# composed_of :address, class_name: "Address",
|
|
||||||
# mapping: [%w(address_street street), %w(address_city city)]
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# Then:
|
|
||||||
#
|
|
||||||
# { address: Address.new("813 abc st.", "chicago") }
|
|
||||||
# # => { address_street: "813 abc st.", address_city: "chicago" }
|
|
||||||
def expand_hash_conditions_for_aggregates(attrs) # :doc:
|
|
||||||
expanded_attrs = {}
|
|
||||||
attrs.each do |attr, value|
|
|
||||||
if aggregation = reflect_on_aggregation(attr.to_sym)
|
|
||||||
mapping = aggregation.mapping
|
|
||||||
mapping.each do |field_attr, aggregate_attr|
|
|
||||||
expanded_attrs[field_attr] = if value.is_a?(Array)
|
|
||||||
value.map { |it| it.send(aggregate_attr) }
|
|
||||||
elsif mapping.size == 1 && !value.respond_to?(aggregate_attr)
|
|
||||||
value
|
|
||||||
else
|
|
||||||
value.send(aggregate_attr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
expanded_attrs[attr] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
expanded_attrs
|
|
||||||
end
|
|
||||||
deprecate :expand_hash_conditions_for_aggregates
|
|
||||||
|
|
||||||
def replace_bind_variables(statement, values)
|
def replace_bind_variables(statement, values)
|
||||||
raise_if_bind_arity_mismatch(statement, statement.count("?"), values.size)
|
raise_if_bind_arity_mismatch(statement, statement.count("?"), values.size)
|
||||||
bound = values.dup
|
bound = values.dup
|
||||||
|
|
|
@ -168,12 +168,6 @@ class SanitizeTest < ActiveRecord::TestCase
|
||||||
assert_equal "#{ActiveRecord::Base.connection.quote('10')}::integer '2009-01-01'::date", l.call
|
assert_equal "#{ActiveRecord::Base.connection.quote('10')}::integer '2009-01-01'::date", l.call
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_deprecated_expand_hash_conditions_for_aggregates
|
|
||||||
assert_deprecated do
|
|
||||||
assert_equal({ "balance" => 50 }, Customer.send(:expand_hash_conditions_for_aggregates, balance: Money.new(50)))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def bind(statement, *vars)
|
def bind(statement, *vars)
|
||||||
if vars.first.is_a?(Hash)
|
if vars.first.is_a?(Hash)
|
||||||
|
|
Loading…
Reference in a new issue