diff options
author | orekyuu <orekyuu@pixiv.com> | 2018-01-26 10:29:41 +0900 |
---|---|---|
committer | orekyuu <orekyuu@pixiv.com> | 2018-01-26 10:29:41 +0900 |
commit | c9822ace4c8961336527670e7eef59093f515dfd (patch) | |
tree | f7b1f56ae2fb5013fa5dbcf70d0976c8fa74afad /activerecord/lib/active_record | |
parent | bbed4c32e469ee74718d5a9cc52792cb473700b9 (diff) | |
download | rails-c9822ace4c8961336527670e7eef59093f515dfd.tar.gz rails-c9822ace4c8961336527670e7eef59093f515dfd.tar.bz2 rails-c9822ace4c8961336527670e7eef59093f515dfd.zip |
Fix not expanded problem when passing an Array object as argument to the where method using composed_of column.
Fixes #31723
```
david_balance = customers(:david).balance
Customer.where(balance: [david_balance]).to_sql
# Before: WHERE `customers`.`balance` = NULL
# After : WHERE `customers`.`balance` = 50
```
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/sanitization.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 58da106092..4acc491104 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -155,10 +155,14 @@ module ActiveRecord if aggregation = reflect_on_aggregation(attr.to_sym) mapping = aggregation.mapping mapping.each do |field_attr, aggregate_attr| - if mapping.size == 1 && !value.respond_to?(aggregate_attr) - expanded_attrs[field_attr] = value + expanded_attrs[field_attr] = if mapping.size == 1 && !value.respond_to?(aggregate_attr) + if value.is_a?(Array) + value.map { |it| it.respond_to?(aggregate_attr) ? it.send(aggregate_attr) : it } + else + value + end else - expanded_attrs[field_attr] = value.send(aggregate_attr) + value.send(aggregate_attr) end end else |