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

Wrong metadata_name

    • Type: Icon: Task Task
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None

      I'm working on a DNS management API and I run in a strange issue with polymorphic embedding.

      I have these models:

      Unable to find source-code formatter for language: `ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class DNS::Zone
        include Mongoid::Document
        embeds_many :rrsets, class_name: 'DNS::RRSet',  inverse_of: :zone
        embeds_one  :soa,    class_name: 'DNS::Record', as: :container
        [...]
      
      class DNS::RRSet
        include Mongoid::Document
        embedded_in :zone, class_name: 'DNS::Zone',   inverse_of: :rrsets
        embeds_many :records, class_name: 'DNS::Record', as: :container
        [...]
      
      class DNS::Record
        include Mongoid::Document
        embedded_in :container, polymorphic: true
        [...]
      

      `

      So I have one record embedded in the Zone and many records embedded in RRSet.

      When assiging the soa record to the zone, everything works fine, but when trying to replace it, or just delete it, I get this:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      NoMethodError: undefined method `records' for #<DNS::Zone:0x00000009bbf298>
      from /usr/local/rvm/gems/ruby-2.1.5/bundler/gems/mongoid-8f22ade5fda8/lib/mongoid/traversable.rb:109:in `remove_child'
      

      `
      This records name is provided by #metadata_name, which returns :records instead of :soa.

      Now the strange part: In its code, #metadata_name just returns __metadata.name but:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      z.soa.metadata_name
      => :records
      z.soa.__metadata.name
      => :soa
      

      `

      And when adding puts __metadata.inspect in #metadata_name, I get this:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      z.soa.metadata_name
      #<Mongoid::Relations::Metadata
        autobuild:    false
        class_name:   DNS::Record
        cyclic:       nil
        counter_cache:false
        dependent:    nil
        inverse_of:   nil
        key:          records
        macro:        embeds_many
        name:         records
        order:        nil
        polymorphic:  true
        relation:     Mongoid::Relations::Embedded::Many
        setter:       records=>
      => :records
      puts z.soa.__metadata.inspect
      #<Mongoid::Relations::Metadata
        autobuild:    false
        class_name:   DNS::Record
        cyclic:       nil
        counter_cache:false
        dependent:    nil
        inverse_of:   :container
        key:          soa
        macro:        embeds_one
        name:         soa
        order:        nil
        polymorphic:  true
        relation:     Mongoid::Relations::Embedded::One
        setter:       soa=>
      

      `

      # metadata_name leads to the wrong relation. When can this wrong metadata object come from ?

            Assignee:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Reporter:
            gauthier-delacroix gauthier-delacroix
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: