aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-07-16 10:09:57 +0200
committerGitHub <noreply@github.com>2017-07-16 10:09:57 +0200
commitf3d67e67abc1fc40b691372af318ede8e30fc4bf (patch)
tree301350f925e10f533c75923585a0f84d99828897 /activerecord/lib/active_record/associations
parent1766e8e6ff9133b8254937791d48eedf2a3f7864 (diff)
parent01c85097d4977b0c141b7c89df15c0750f37c62d (diff)
downloadrails-f3d67e67abc1fc40b691372af318ede8e30fc4bf.tar.gz
rails-f3d67e67abc1fc40b691372af318ede8e30fc4bf.tar.bz2
rails-f3d67e67abc1fc40b691372af318ede8e30fc4bf.zip
Merge pull request #29771 from kamipo/fix_create_with_using_both_string_and_symbol
Fix `create_with` using both string and symbol
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association.rb7
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb4
-rw-r--r--activerecord/lib/active_record/associations/singular_association.rb5
3 files changed, 7 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 1138ae3462..6acf831759 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -171,8 +171,8 @@ module ActiveRecord
skip_assign = [reflection.foreign_key, reflection.type].compact
assigned_keys = record.changed_attribute_names_to_save
assigned_keys += except_from_scope_attributes.keys.map(&:to_s)
- attributes = create_scope.except(*(assigned_keys - skip_assign))
- record.assign_attributes(attributes)
+ attributes = scope_for_create.except(*(assigned_keys - skip_assign))
+ record.send(:_assign_attributes, attributes) if attributes.any?
set_inverse_instance(record)
end
@@ -185,6 +185,9 @@ module ActiveRecord
end
private
+ def scope_for_create
+ scope.scope_for_create
+ end
def find_target?
!loaded? && (!owner.new_record? || foreign_key_present?) && klass
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index a49fb155ee..69401162aa 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -374,10 +374,6 @@ module ActiveRecord
end
end
- def create_scope
- scope.scope_for_create.stringify_keys
- end
-
def delete_or_destroy(records, method)
records = records.flatten
records.each { |record| raise_on_type_mismatch!(record) }
diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb
index f8bbe4c2ed..4896afcca7 100644
--- a/activerecord/lib/active_record/associations/singular_association.rb
+++ b/activerecord/lib/active_record/associations/singular_association.rb
@@ -30,9 +30,8 @@ module ActiveRecord
end
private
-
- def create_scope
- scope.scope_for_create.stringify_keys.except(klass.primary_key)
+ def scope_for_create
+ super.except(klass.primary_key)
end
def find_target