Skip to content

Commit d23c332

Browse files
jonleightontenderlove
authored andcommitted
Clean up create, create! and build in HasOneAssociation
1 parent 5ecf692 commit d23c332

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

activerecord/lib/active_record/associations/has_one_association.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@ module ActiveRecord
22
# = Active Record Belongs To Has One Association
33
module Associations
44
class HasOneAssociation < AssociationProxy #:nodoc:
5-
def create(attrs = {})
6-
new_record do |reflection|
7-
reflection.create_association(attrs)
8-
end
5+
def create(attributes = {})
6+
new_record(:create_association, attributes)
97
end
108

11-
def create!(attrs = {})
12-
new_record do |reflection|
13-
reflection.create_association!(attrs)
14-
end
9+
def create!(attributes = {})
10+
new_record(:create_association!, attributes)
1511
end
1612

17-
def build(attrs = {})
18-
new_record do |reflection|
19-
reflection.build_association(attrs)
20-
end
13+
def build(attributes = {})
14+
new_record(:build_association, attributes)
2115
end
2216

2317
def replace(obj, dont_save = false)
@@ -69,8 +63,8 @@ def association_scope
6963

7064
alias creation_attributes construct_owner_attributes
7165

72-
def new_record
73-
record = scoped.scoping { yield @reflection }
66+
def new_record(method, attributes)
67+
record = scoped.scoping { @reflection.send(method, attributes) }
7468
replace(record, true)
7569
record
7670
end

0 commit comments

Comments
 (0)