3 class BelongsToAssociation
< AssociationProxy
#:nodoc:
4 def create(attributes
= {})
5 replace(@reflection.create_association(attributes
))
8 def build(attributes
= {})
9 replace(@reflection.build_association(attributes
))
13 counter_cache_name
= @reflection.counter_cache_column
16 if counter_cache_name
&& !@owner.new_record
?
17 @reflection.klass
.decrement_counter(counter_cache_name
, @owner[@reflection.primary_key_name
]) if @owner[@reflection.primary_key_name
]
20 @target = @owner[@reflection.primary_key_name
] = nil
22 raise_on_type_mismatch(record
)
24 if counter_cache_name
&& !@owner.new_record
?
25 @reflection.klass
.increment_counter(counter_cache_name
, record
.id
)
26 @reflection.klass
.decrement_counter(counter_cache_name
, @owner[@reflection.primary_key_name
]) if @owner[@reflection.primary_key_name
]
29 @target = (AssociationProxy
=== record
? record
.target
: record
)
30 @owner[@reflection.primary_key_name
] = record
.id
unless record
.new_record
?
44 @reflection.klass
.find(
45 @owner[@reflection.primary_key_name
],
46 :select => @reflection.options
[:select],
47 :conditions => conditions
,
48 :include => @reflection.options
[:include],
49 :readonly => @reflection.options
[:readonly]
53 def foreign_key_present
54 !@owner[@reflection.primary_key_name
].nil?