to_json does not include _type field

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The to_json method does not include the _type attribute in the output. Take the following models:

      class Pet
        include Mongoid::Document
        field :name, type: String
      end
      
      class Dog < Pet
        field :breed, type: String
        field :average_weight, type: Integer
      end
      
      class Cat < Pet
        field :minion_strength, type: Integer
      end
      
      Dog.create!
      Cat.create!
      puts Pet.all.to_json
      # does not include _type
      

      This ticket should investigate why this is and if it is intentional.

      This is a followup on the following discussion: https://github.com/mongodb/mongoid/discussions/5155

            Assignee:
            Neil Shweky (Inactive)
            Reporter:
            Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: