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

Finding by embedded document parent raises NoMethodError: undefined method `__bson_dump__'

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Resolution: Done
    • None
    • 3.1.5
    • None

    Description

      It looks like the object isn't being converted to a param? The example isn't the best but it shows the error. This seems to only happen in embedded documents, referenced documents work fine. The workaround for now was to call

      .id

      or

      .to_param

      but it'd be great to find a longer term fix. Thanks!

      class Group
        include Mongoid::Document
        field :name, type: String
        embeds_many :users
      end
       
      class User
        include Mongoid::Document
        field :name, type: String
        embedded_in :group
      end
       
      group = Group.new(name: 'Foo Co')
      group.users << User.new(name: 'John Bar')
      group.save
       
      irb(main):012:0> Group.first === Group.first.users.first.group
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (1.5523ms)
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.8321ms)
      => true
       
      Group.find(Group.first)
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (1.1330ms)
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"_id"=>"52161977d43dcdde4e000002"} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.8149ms)
      => #<Group _id: 52161977d43dcdde4e000002, name: "Foo Co">
       
      Group.find(Group.first.users.first.group)
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (1.2069ms)
        MOPED: 127.0.0.1:27017 QUERY        database=testing_development collection=groups selector={"_id"=>#<Group _id: 52161977d43dcdde4e000002, name: "Foo Co">} flags=[:slave_ok] limit=0 skip=0 batch_size=nil fields=nil (0.4301ms)
      NoMethodError: undefined method `__bson_dump__' for #<Group _id: 52161977d43dcdde4e000002, name: "Foo Co">
      

      Attachments

        Activity

          People

            durran Durran Jordan
            jfine jfine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: