Sha256: fc752c25e9cd259824eda251c7cd916c7aac57b9ea31a294f842ca6f0e0bf316
Contents?: true
Size: 733 Bytes
Versions: 5
Compression:
Stored size: 733 Bytes
Contents
module ActiveForce module Association class BelongsToAssociation < Association private def default_foreign_key infer_foreign_key_from_model relation_model end def define_relation_method association = self _method = @relation_name @parent.send :define_method, _method do association_cache.fetch(_method) do association_cache[_method] = association.relation_model.find(send association.foreign_key) end end @parent.send :define_method, "#{_method}=" do |other| send "#{ association.foreign_key }=", other.nil? ? nil : other.id association_cache[_method] = other end end end end end
Version data entries
5 entries across 5 versions & 2 rubygems