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

`method_missing': undefined method `__bson_dump__' for #<Location:0x007fee4b8b2248> (NoMethodError)

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

      I have a model server.rb, in it I have:

      belongs_to :location
      

      I also have a model called zone.rb where I also have:

      belongs_to :location
      

      When I try to do:

      zone = Zone.find_or_create_by(
        :name => "Test Name",
        :location => Server.first.location
      )
      

      I get this exception:

      /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/attributes.rb:225:in `method_missing': undefined method `__bson_dump__' for #<Location:0x007fee4b8b2248> (NoMethodError)
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/relations/proxy.rb:117:in `method_missing'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:36:in `block in __bson_dump__'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:35:in `each'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:35:in `__bson_dump__'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:36:in `block in __bson_dump__'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:35:in `each'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/extensions/hash.rb:35:in `__bson_dump__'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/bson/document.rb:11:in `serialize'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/protocol/message.rb:136:in `serialize_selector'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/protocol/message.rb:289:in `serialize'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/connection.rb:143:in `block in write'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/connection.rb:141:in `each'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/connection.rb:141:in `write'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:517:in `block (2 levels) in flush'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:123:in `ensure_connected'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:516:in `block in flush'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:531:in `logging'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:515:in `flush'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:504:in `process'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:343:in `query'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/session/context.rb:44:in `block in query'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/session/context.rb:109:in `block in with_node'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/cluster.rb:150:in `block in with_primary'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/node.rb:168:in `ensure_primary'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/cluster.rb:149:in `with_primary'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/session/context.rb:108:in `with_node'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/session/context.rb:43:in `query'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/moped-1.2.1/lib/moped/query.rb:109:in `first'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/contextual/mongo.rb:202:in `first'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/contextual.rb:18:in `first'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/finders.rb:144:in `find_or'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-3.0.5/lib/mongoid/finders.rb:74:in `find_or_create_by'
      	from lib/tools/import_events.rb:17:in `block in <top (required)>'
      	from lib/tools/import_events.rb:6:in `each'
      	from lib/tools/import_events.rb:6:in `<top (required)>'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/runner.rb:51:in `eval'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/runner.rb:51:in `<top (required)>'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:64:in `require'
      	from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:64:in `<top (required)>'
      	from script/rails:6:in `require'
      	from script/rails:6:in `<main>'
      

      Why is this?

      If I however get the location with Location.first instead of getting it through Server.first.location, it works. Shouldn't it work if I try to get location through the Server model?

            Assignee:
            Unassigned Unassigned
            Reporter:
            hackeron Roman Gaufman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: