Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3285

group_by on _type fails on base class objects

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I have model base class that other models extend. I use this base class to store generic data. This results in one collection storing all objects from all these classes.

      When I try to run: {{BaseModel.all.group_by

      { |obj| obj._type }

      .keys}}

      I get exception on base class objects missing _type property. This is not true, since these objects have this property in the database. For some reason base class doesn't promote the _type property.

      `NoMethodError: undefined method _type for #<BaseModel:0x007fb9668da640>
      from (irb):1:in block in irb_binding
      from /Users/napalm/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-88599cf64c3d/lib/mongoid/contextual/mongo.rb:671:in yield_document
      from /Users/napalm/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mongoid-88599cf64c3d/lib/mongoid/contextual/mongo.rb:124:in block (2 levels) in each`

            Assignee:
            Unassigned Unassigned
            Reporter:
            kixorz kixorz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: