mongoid/mongoid — Issue #1533: ActiveModel breaks inheritance
Author: canavese
Created: 2011-12-29 19:45:15+00:00
State: open

I just tried upgrading to Rails 3.2.0.rc1 and found that it had an odd effect on one of my inherited documents. An exception is thrown if I try to access a field defined in the document subclass, although fields defined in the superclass are fine. I have reverted so this isn't a significant issue for me right now, but you might want to be aware of this.

```ruby
class Region
include Mongoid::Document

field :population, type: Integer
...
end

class City < Region
field :state_code, type: String
...
end
```

```
> c = City.first
=> #
> c.state_code
NoMethodError: undefined method `attribute' for #
from /gems/activemodel-3.2.0.rc1/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /gems/mongoid-2.3.3/lib/mongoid/attributes.rb:184:in `method_missing'
from /gems/activemodel-3.2.0.rc1/lib/active_model/attribute_methods.rb:345:in `state_code'
from (irb):2
from /gems/railties-3.2.0.rc1/lib/rails/commands/console.rb:47:in `start'
from /gems/railties-3.2.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /gems/railties-3.2.0.rc1/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

> c.population
=> 72259
```