Class: Superstore::Associations::BelongsTo
Instance Attribute Summary
Attributes inherited from Association
#owner, #reflection
Instance Method Summary
collapse
Methods inherited from Association
#association_class, #association_class_name, #initialize, #loaded!, #loaded?, #reset, #target, #target=
Instance Method Details
#belongs_to? ⇒ Boolean
20
|
# File 'lib/superstore/associations/belongs_to.rb', line 20
def belongs_to?; true; end
|
#reader ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/superstore/associations/belongs_to.rb', line 4
def reader
unless loaded?
self.target = get_record
end
target
end
|
#writer(record) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/superstore/associations/belongs_to.rb', line 12
def writer(record)
self.target = record
owner.send("#{reflection.foreign_key}=", record.try(reflection.primary_key))
if reflection.polymorphic?
owner.send("#{reflection.polymorphic_column}=", record.class.name)
end
end
|