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

Mongoid STI get properly casted objects

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      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,

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: