lib/mongo_mapper/plugins/sci.rb in mongo_mapper-0.9.1 vs lib/mongo_mapper/plugins/sci.rb in mongo_mapper-0.9.2
- old
+ new
@@ -2,10 +2,14 @@
module MongoMapper
module Plugins
module Sci
extend ActiveSupport::Concern
+ included do
+ extend ActiveSupport::DescendantsTracker
+ end
+
module ClassMethods
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?
@@ -16,11 +20,11 @@
@single_collection_inherited == true
end
def query(options={})
super.tap do |query|
- query[:_type] = name if single_collection_inherited?
+ query[:_type] = {'$in' => [name] + descendants.map(&:name)} if single_collection_inherited?
end
end
end
module InstanceMethods
@@ -29,6 +33,6 @@
write_key :_type, self.class.name if self.class.key?(:_type)
end
end
end
end
-end
\ No newline at end of file
+end