mongoid/mongoid — Issue #1434: HABTM 2.3.3: NoMethodError: undefined method `compact'
Author: bdmac
Created: 2011-11-18 04:51:27+00:00
State: open

I'm not sure what's going on here but with my current relations I'm getting a `NoMethodError: undefined method `compact'` under Mongoid 2.3.3.

Here's an example that recreates the problem. Apologies for the ridiculousness of the models.

``` ruby
class Movie
include Mongoid::Document
belongs_to :initial_reviewer, class_name: 'Reviewer'
end

class Reviewer
include Mongoid::Document
has_and_belongs_to_many :movies, inverse_of: nil
end
```

If you then attempt to do `Movie.new.initial_reviewer = Reviewer.new` you will get the previously mentioned error. Here's the stack:

```
NoMethodError: undefined method `compact' for #
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/activemodel-3.1.1/lib/active_model/attribute_methods.rb:385:in `method_missing'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/attributes.rb:184:in `method_missing'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/many.rb:298:in `block in substitute'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/many.rb:295:in `tap'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/many.rb:295:in `substitute'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/accessors.rb:128:in `block (2 levels) in setter'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/extensions/object/yoda.rb:23:in `do_or_do_not'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/bindings/referenced/in.rb:36:in `block in bind'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/threaded/lifecycle.rb:55:in `_binding'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/bindings/referenced/in.rb:23:in `bind'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/proxy.rb:20:in `bind_one'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/in.rb:24:in `block in initialize'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/proxy.rb:35:in `init'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/referenced/in.rb:22:in `initialize'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/accessors.rb:44:in `new'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/accessors.rb:44:in `create_relation'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/accessors.rb:26:in `build'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/mongoid-2.3.3/lib/mongoid/relations/accessors.rb:130:in `block (2 levels) in setter'
from (irb):3
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /Users/bmcmanus/.rvm/gems/ruby-1.9.2-p290@trazzler/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'
```