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

Mongoid STI get properly casted objects

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi,

      I end up posting an issue since ActiveRecord does the STI conversion by default.

      Considering the following code:

      class User
        include Mongoid::Document
        embeds_many :base_foos
      end
      
      class BaseFoo
        include Mongoid::Document
        embedded_in :user
      end
      
      class Bar < BaseFoo
      end
      
      class Baz < BaseFoo
      end
      

      `
      When I do:

      user.base_foos

      Could I somehow have the objects casted in their proper type (without breaking lazy load)?

      ie , I'd like to get Bar}}s and {{Baz}}s, no {{BaseFoos.

      I'm using Mongoid 2.4.9 and also checked with 2.6.0.

      Thanks,

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

              Created:
              Updated:
              Resolved: