With these models:
models/asset.rb
class Asset < Entity
include Mongoid::Document
end
models/assets/text.rb
module Assets
class Text < Asset
include Mongoid::Document
store_in collection: "#{tenant_uuid}_contents"
end
end
the Rails console returns:
Entity.all.entries
MOPED: 127.0.0.1:27017 QUERY database=dbname collection=entities selector={} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.3572ms) []
Asset.all.entries
MOPED: 127.0.0.1:27017 QUERY database=dbname collection=2b66d7a9-8cb5-4802-838a-f1f58869bbf5_contents selector={"$query"=>{"_type"=>{"$in"=>["Asset"]}}, "$orderby"=>{"_id"=>1}} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.9501ms) []
But if I then do Entity.all.entries again (ie. after Asset.all.entries) I get a different response:
Entity.all.entries
MOPED: 127.0.0.1:27017 QUERY database=dbname collection=2b66d7a9-8cb5-4802-838a-f1f58869bbf5_contents selector={} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (3.2308ms)
MOPED: 127.0.0.1:27017 GET_MORE .... and all documents are returned here
If I remove the fact that Asset inherits from Entity, then
Assets.all.entries
always works the first time and returns all documents.
So there is something I am not understanding about the inheritance chain here. Or the fact that Entity is not stored in the contents collection - it is like an 'abstract' class (the Entity class is inherited by other objects which are stored in their own respective collections).
So is the problem here that Mongoid cannot support such an inheritance structure? Do we HAVE to store Entity in the same collection as its children?
Thanks in advance.