Class: MongoModel::Associations::BelongsTo::Association
Instance Attribute Summary
#definition, #instance
Instance Method Summary
collapse
#ensure_class, #initialize, #proxy
Instance Method Details
#find_target ⇒ Object
68
69
70
|
# File 'lib/mongomodel/concerns/associations/belongs_to.rb', line 68
def find_target
target_class.find(target_id) if target_id && target_class
end
|
#replace(obj) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/mongomodel/concerns/associations/belongs_to.rb', line 59
def replace(obj)
ensure_class(obj) if obj && !polymorphic?
instance[foreign_key] = obj ? obj.id : nil
instance[type_key] = obj ? obj.class : nil if polymorphic?
super
end
|
#target_class ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/mongomodel/concerns/associations/belongs_to.rb', line 51
def target_class
if polymorphic?
instance[type_key].constantize rescue nil
else
klass
end
end
|
#target_id ⇒ Object
47
48
49
|
# File 'lib/mongomodel/concerns/associations/belongs_to.rb', line 47
def target_id
instance[foreign_key]
end
|