Class: ActiveData::Model::Attributes::ReferenceOne
- Inherits:
-
Base
- Object
- Base
- ActiveData::Model::Attributes::ReferenceOne
show all
- Defined in:
- lib/active_data/model/attributes/reference_one.rb
Instance Attribute Summary
Attributes inherited from Base
#name, #owner
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #inspect_attribute, #pollute, #query, #readonly?, #reflection, #reset, #typecast, #value_present?, #write_value
Instance Method Details
#read ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/active_data/model/attributes/reference_one.rb', line 16
def read
if association.target
association.identify
else
type_casted_value
end
end
|
#read_before_type_cast ⇒ Object
24
25
26
|
# File 'lib/active_data/model/attributes/reference_one.rb', line 24
def read_before_type_cast
@value_cache
end
|
#write(value) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/active_data/model/attributes/reference_one.rb', line 5
def write value
pollute do
previous = type_casted_value
result = write_value value
if (!value.nil? && type_casted_value.nil?) || type_casted_value != previous
association.reset
end
result
end
end
|