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

ActiveModel breaks inheritance

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

      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.

      class Region
        include Mongoid::Document
      
        field :population,              type: Integer
        ...
      end
      
      class City < Region
        field :state_code, type: String
        ...
      end
      
      > c = City.first
       => #<City _id: 4ecc093f1bead23de3000127, _type: "City", geo: [37.7507, -122.235], region_ids: [BSON::ObjectId('4ecc09381bead23de3000005'), BSON::ObjectId('4ecc093a1bead23de300003d'), BSON::ObjectId('4ecc093a1bead23de300003e')], bbox: nil, bounds: nil, name: "Alameda", key: "alameda", description: nil, sub_type: "city", mysql_id: 301696, parent_id: nil, population: 72259, default_address_id: BSON::ObjectId('4ecc0a321bead23de3008044'), state_code: "CA"> 
      > c.state_code
      NoMethodError: undefined method `attribute' for #<City:0x00000104343a50>
      	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 `<top (required)>'
      	from script/rails:6:in `require'
      	from script/rails:6:in `<main>
      > c.population
       => 72259 
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            canavese Paul Canavese
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: