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

parent.child = Child.new raises TypeError when there's no inverse relation for belongs_to with has_one parent

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.2.0
    • Component/s: Associations
    • Labels:
    • Backwards Compatibility:
      Minor Change

      Description

      require 'bundler/inline'
       
      gemfile do
        source 'https://rubygems.org'
       
        gem 'mongoid'
      end
       
      require 'tempfile'
       
      Tempfile.open(%w(config .yml)) do |f|
        uri = 'mongodb://mongo/test'
       
        f.write(<<~YAML)
      development:
        clients:
          default:
            uri: #{uri}
        YAML
        f.flush
       
        Mongoid.load!(f.path, 'development')
        Mongoid::Clients.clients.each do |_, client|
          client.logger.level = Logger::ERROR
        end
      end
       
      class Parent
        include Mongoid::Document
       
        has_one :child
      end
       
      class Child
        include Mongoid::Document
      end
       
      Parent.new.child = Child.new
       
      __END__
      Traceback (most recent call last):
              7: from hi.rb:38:in `<main>'
              6: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/accessors.rb:290:in `block (2 levels) in define_setter!'
              5: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/accessors.rb:183:in `without_autobuild'
              4: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/accessors.rb:299:in `block (3 levels) in define_setter!'
              3: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/accessors.rb:30:in `__build__'
              2: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/accessors.rb:50:in `create_relation'
              1: from /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/referenced/has_one/buildable.rb:30:in `build'
      /usr/local/bundle/gems/mongoid-7.1.2/lib/mongoid/association/referenced/has_one/buildable.rb:38:in `clear_associated': nil is not a symbol nor a string (TypeError)
      

      Is this intentional?

        Attachments

          Activity

            People

            Assignee:
            oleg.pudeyev Oleg Pudeyev
            Reporter:
            mtsmfm@quipper.com Fumiaki Matsushima
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: