Sha256: 83abf43c3c6088331a4c75cdd9cdd76ca73fed8aa25959a9251cf6f6449a5c97
Contents?: true
Size: 1.07 KB
Versions: 11
Compression:
Stored size: 1.07 KB
Contents
module ActiveForce module Association class BelongsToAssociation < Association def relationship_name options[:relationship_name] || default_relationship_name end private def loadable?(owner) foreign_key_value(owner).present? end def target(owner) relation_model.find(foreign_key_value(owner)) end def default_relationship_name if !parent.custom_table? && !relation_model.custom_table? relation_model.table_name else parent.mappings[foreign_key].gsub(/__c\z/, '__r') end end def default_foreign_key infer_foreign_key_from_model relation_model end def foreign_key_value(owner) owner&.public_send(foreign_key) end def define_assignment_method association = self method_name = relation_name parent.send :define_method, "#{method_name}=" do |other| send "#{association.foreign_key}=", other&.id association_cache[method_name] = other end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems