Sha256: b5ff88f5b48a3099bba237b808a2a0fa8166a60001f7c9ad86c6e08c2e6e6bdf
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true module Mongoload module RelationsAccessorsWithAutoInclude private_class_method def self.assign_missing_proxy_method(relation) if relation.class == Mongoid::Relations::Targets::Enumerable relation.target.define_singleton_method :relation_metadata do relation.relation_metadata end relation.target.define_singleton_method :base do relation.base end end end private def get_relation(name, metadata, object, reload=false) # has_one and belongs_to will return the value immediately # while other relation are lazy if [Mongoid::Relations::Referenced::In, Mongoid::Relations::Referenced::One].include?(metadata.relation) Mongoload::RelationLoader.load(self, metadata) if !object.is_a?(metadata.klass) && ivar(name) == false end result = super result.tap do |relation| Mongoload::RelationsAccessorsWithAutoInclude.assign_missing_proxy_method(relation) end end end end Mongoid::Document.prepend Mongoload::RelationsAccessorsWithAutoInclude
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoload-0.0.3 | lib/mongoload/patches/relations_accessors.rb |