Sha256: 4921275bf7fdc3e7c8f24897b8b84e30c308741d8da85e83a6973965d765dab5
Contents?: true
Size: 965 Bytes
Versions: 2
Compression:
Stored size: 965 Bytes
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 parent.mappings[foreign_key].gsub(/__c\z/, '__r') 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_force-0.15.1 | lib/active_force/association/belongs_to_association.rb |
active_force-0.15.0 | lib/active_force/association/belongs_to_association.rb |