Module: MongoMapper::Plugins::Sci::ClassMethods

Defined in:
lib/mongo_mapper/plugins/sci.rb

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



12
13
14
15
16
17
# File 'lib/mongo_mapper/plugins/sci.rb', line 12

def inherited(subclass)
  key :_type, String unless key?(:_type)
  subclass.instance_variable_set("@single_collection_inherited", true)
  subclass.set_collection_name(collection_name) unless subclass.embeddable?
  super
end

#query(options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/mongo_mapper/plugins/sci.rb', line 23

def query(options={})
  super.tap do |query|
    query[:_type] = {'$in' => [name] + descendants.map(&:name)} if single_collection_inherited?
  end
end

#single_collection_inherited?Boolean

Returns:



19
20
21
# File 'lib/mongo_mapper/plugins/sci.rb', line 19

def single_collection_inherited?
  @single_collection_inherited == true
end