@@ -2,22 +2,16 @@ module ActiveRecord
2
2
# = Active Record Belongs To Has One Association
3
3
module Associations
4
4
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 )
9
7
end
10
8
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 )
15
11
end
16
12
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 )
21
15
end
22
16
23
17
def replace ( obj , dont_save = false )
@@ -69,8 +63,8 @@ def association_scope
69
63
70
64
alias creation_attributes construct_owner_attributes
71
65
72
- def new_record
73
- record = scoped . scoping { yield @reflection }
66
+ def new_record ( method , attributes )
67
+ record = scoped . scoping { @reflection . send ( method , attributes ) }
74
68
replace ( record , true )
75
69
record
76
70
end
0 commit comments