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

write_attributes fails. It is not creating documents and thus trying to reindex a hash/array

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

      When you call something like .write_attributes([{:title => "foo"}]) on an existing association it bombs with the following error:

      Unable to find source-code formatter for language: failure. 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
      /Error: person.write_attributes({:videos => [{:title => "Hackers"}]})
           NoMethodError:
             undefined method `_index=' for {:title=>"Hackers"}:Hash
      

      this is due to the reindex method being called on the hash, instead of first creating a document, it appears as if the substitute method is not building a new document just passing around the Hash.

      I'm unsure of the correct way to fix this, as there are a lot of tests ensuring that the same relationship is used, and old data is run through unbind etc.

      I have created a failing test case in my branch for anyone interested in giving it a look

      https://github.com/erikstmartin/mongoid/commit/7a235258fbb7dc1059c2fa03e3ffe69369e0cce2

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

              Created:
              Updated:
              Resolved: