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

undefined method `inverse_of_field' for nil:NilClass (on Heroku)

      I've run into an error "undefined method `inverse_of_field' for nil:NilClass", just as was reported in MONGOID-2323, however my models don't have relationships so I can't "fix" it as the person who created that issue could.

      I'm running ruby 1.9.3 and using Mongoid 3.0.19, and when I push my app to heroku I am unable to "update" a Post (see models in a moment), but when I run locally I have no issues.

      Here's my models:

      module CmsSupport
        class WebDocument
          include Mongoid::Document
          include Mongoid::Timestamps
      
          before_save :translate_slug
      
          field :title, :type=>String
          field :content, :type=>String
          field :slug, :type=>String
          field :published, :type=>Boolean, :default=>false
      
          validates_presence_of :title, :content
          validates_uniqueness_of :title
      
          def translate_slug
            self.slug = self.title.parameterize('-')
          end
        end
      end
      
      module CmsSupport
        class Post < WebDocument
          field :author, type: String
          field :tags, type: Array, default: []
      
          validates_presence_of :author
        end
      end
      

      I have an existing CmsSupport::Post that I'm trying to update.

      I'm doing the following in from my controller:

      id = params.delete "id"
      post = CmsSupport::Post.find id
      post.update_attributes! params
      

      Here's the params after the "id" was removed:

      {"created_at"=>"2013-01-08T15:49:33Z", "updated_at"=>"2013-01-08T15:49:33Z", "title"=>"Blog has Gone Live",             "content"=>"The blog has finally gone live, although a few bugs still need be ironed out now that it's been deployed.",       "slug"=>"blog-has-gone-live", "published"=>false, "author"=>"craig", "tags"=>nil}
      

      Here's a full stacktrace:

      Internal server error occurred: undefined method `inverse_of_field' for nil:NilClass:
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/referenced/one.rb:131:in `criteria'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/metadata.rb:153:in `criteria'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/builders/referenced/one.rb:20:in `build'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:43:in `create_relation'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:26:in `__build__'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:120:in `block (2 levels) in get_relation'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/threaded/lifecycle.rb:125:in `_loading'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:115:in `block in get_relation'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:114:in `get_relation'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/relations/accessors.rb:203:in `block in getter'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/validations.rb:54:in `read_attribute_for_validation'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validator.rb:151:in `block in validate'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validator.rb:150:in `each'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validator.rb:150:in `validate'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:310:in `_callback_before_25'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:440:in `_run__1708332970271307486__validate__2478065345932905662__callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/callbacks.rb:114:in `run_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validations.rb:228:in `run_validations!'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:403:in `_run__1708332970271307486__validation__2478065345932905662__callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/callbacks.rb:114:in `run_callbacks'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validations.rb:195:in `valid?'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/validations.rb:78:in `valid?'
       /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.2.11/lib/active_model/validations.rb:203:in `invalid?'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence/modification.rb:22:in `prepare'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence/operations/update.rb:43:in `persist'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence.rb:139:in `update'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence.rb:81:in `save'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence.rb:175:in `update_attributes'
       /app/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.19/lib/mongoid/persistence.rb:190:in `update_attributes!'
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            mindscratch mindscratch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: