aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2012-09-18 12:33:13 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2012-09-18 12:33:13 -0700
commitc49d959e9d40101f1712a452004695f4ce27d84c (patch)
treef87077668c14ed414e3d819212b0813e74551c8f /activerecord/lib/active_record/associations
parentade701045f0f80399d99151e5583d4f86c68678e (diff)
parent3919fcd61ef999aab9397332ce3017870b184766 (diff)
downloadrails-c49d959e9d40101f1712a452004695f4ce27d84c.tar.gz
rails-c49d959e9d40101f1712a452004695f4ce27d84c.tar.bz2
rails-c49d959e9d40101f1712a452004695f4ce27d84c.zip
Merge pull request #7251 from rails/integrate-strong_parameters
Integrate strong_parameters in Rails 4
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association.rb6
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb20
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb13
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb4
-rw-r--r--activerecord/lib/active_record/associations/singular_association.rb16
5 files changed, 29 insertions, 30 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 9f47e7e631..495f0cde59 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -233,10 +233,10 @@ module ActiveRecord
def stale_state
end
- def build_record(attributes, options)
- reflection.build_association(attributes, options) do |record|
+ def build_record(attributes)
+ reflection.build_association(attributes) do |record|
attributes = create_scope.except(*(record.changed - [reflection.foreign_key]))
- record.assign_attributes(attributes, :without_protection => true)
+ record.assign_attributes(attributes)
end
end
end
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 424c1a5b79..fe3e5b00f7 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -95,22 +95,22 @@ module ActiveRecord
first_or_last(:last, *args)
end
- def build(attributes = {}, options = {}, &block)
+ def build(attributes = {}, &block)
if attributes.is_a?(Array)
- attributes.collect { |attr| build(attr, options, &block) }
+ attributes.collect { |attr| build(attr, &block) }
else
- add_to_target(build_record(attributes, options)) do |record|
+ add_to_target(build_record(attributes)) do |record|
yield(record) if block_given?
end
end
end
- def create(attributes = {}, options = {}, &block)
- create_record(attributes, options, &block)
+ def create(attributes = {}, &block)
+ create_record(attributes, &block)
end
- def create!(attributes = {}, options = {}, &block)
- create_record(attributes, options, true, &block)
+ def create!(attributes = {}, &block)
+ create_record(attributes, true, &block)
end
# Add +records+ to this association. Returns +self+ so method calls may
@@ -425,16 +425,16 @@ module ActiveRecord
persisted + memory
end
- def create_record(attributes, options, raise = false, &block)
+ def create_record(attributes, raise = false, &block)
unless owner.persisted?
raise ActiveRecord::RecordNotSaved, "You cannot call create unless the parent is saved"
end
if attributes.is_a?(Array)
- attributes.collect { |attr| create_record(attr, options, raise, &block) }
+ attributes.collect { |attr| create_record(attr, raise, &block) }
else
transaction do
- add_to_target(build_record(attributes, options)) do |record|
+ add_to_target(build_record(attributes)) do |record|
yield(record) if block_given?
insert_record(record, true, raise)
end
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 66132b7260..c113957faa 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -222,8 +222,8 @@ module ActiveRecord
#
# person.pets.size # => 5 # size of the collection
# person.pets.count # => 0 # count from database
- def build(attributes = {}, options = {}, &block)
- @association.build(attributes, options, &block)
+ def build(attributes = {}, &block)
+ @association.build(attributes, &block)
end
##
@@ -253,8 +253,8 @@ module ActiveRecord
# # #<Pet id: 2, name: "Spook", person_id: 1>,
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
- def create(attributes = {}, options = {}, &block)
- @association.create(attributes, options, &block)
+ def create(attributes = {}, &block)
+ @association.create(attributes, &block)
end
##
@@ -265,14 +265,13 @@ module ActiveRecord
# end
#
# class Pet
- # attr_accessible :name
# validates :name, presence: true
# end
#
# person.pets.create!(name: nil)
# # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
- def create!(attributes = {}, options = {}, &block)
- @association.create!(attributes, options, &block)
+ def create!(attributes = {}, &block)
+ @association.create!(attributes, &block)
end
##
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index d8f14c896c..c7d8a84a7e 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -96,10 +96,10 @@ module ActiveRecord
@through_records.delete(record.object_id)
end
- def build_record(attributes, options = {})
+ def build_record(attributes)
ensure_not_nested
- record = super(attributes, options)
+ record = super(attributes)
inverse = source_reflection.inverse_of
if inverse
diff --git a/activerecord/lib/active_record/associations/singular_association.rb b/activerecord/lib/active_record/associations/singular_association.rb
index b84cb4922d..32f4557c28 100644
--- a/activerecord/lib/active_record/associations/singular_association.rb
+++ b/activerecord/lib/active_record/associations/singular_association.rb
@@ -17,16 +17,16 @@ module ActiveRecord
replace(record)
end
- def create(attributes = {}, options = {}, &block)
- create_record(attributes, options, &block)
+ def create(attributes = {}, &block)
+ create_record(attributes, &block)
end
- def create!(attributes = {}, options = {}, &block)
- create_record(attributes, options, true, &block)
+ def create!(attributes = {}, &block)
+ create_record(attributes, true, &block)
end
- def build(attributes = {}, options = {})
- record = build_record(attributes, options)
+ def build(attributes = {})
+ record = build_record(attributes)
yield(record) if block_given?
set_new_record(record)
record
@@ -51,8 +51,8 @@ module ActiveRecord
replace(record)
end
- def create_record(attributes, options, raise_error = false)
- record = build_record(attributes, options)
+ def create_record(attributes, raise_error = false)
+ record = build_record(attributes)
yield(record) if block_given?
saved = record.save
set_new_record(record)