class MarkMapper::Plugins::Associations::BelongsToPolymorphicProxy

Public Instance Methods

replace(doc) click to toggle source
# File lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb, line 6
def replace(doc)
  if doc
    doc.save unless doc.persisted?
    id, type = doc.id, doc.class.name
  end

  proxy_owner[association.foreign_key] = id
  proxy_owner[association.type_key_name] = type
  reset
  unless doc.nil?
    loaded
    @target = doc
  end

  @target
end

Protected Instance Methods

association_class() click to toggle source
# File lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb, line 29
def association_class
  proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil
end
find_target() click to toggle source
# File lib/mark_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb, line 24
def find_target
  return nil if association_class.nil? || proxy_owner[association.foreign_key].nil?
  association_class.find_by_id(proxy_owner[association.foreign_key])
end