Sha256: fb1fc1f1a9a9629c8a129f82d6b8f9bc36f715975250e2a81464822abec325ad
Contents?: true
Size: 722 Bytes
Versions: 1
Compression:
Stored size: 722 Bytes
Contents
require "preserves/mapper/relation" module Preserves class Mapper class BelongsTo < Relation def map! assign_attribute(object, relation_name, relation_repo.map_one(relation_result_for_this_object)) end def relation_result_for_this_object @relation_result_for_this_object ||= relation_result_set.find{ |r| r[relation_repo.mapping.primary_key] == record.fetch(relation_foreign_key) } end def relation_foreign_key @relation_foreign_key ||= relation_settings.fetch(:foreign_key) { "#{relation_name.downcase}_id" } end def relation_settings @relation_settings ||= mapping.belongs_to_mappings.fetch(relation_name) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
preserves-0.1.0 | lib/preserves/mapper/belongs_to.rb |