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

array attribute changes not persisting when using :default => [] and validations

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      if you have an array field with a a :default => [] and a validation in place, when you update the array attribute by replacing the array, the change won't get saved.

      attached is a set of failing specs in the spec/functional/mongoid/array_validation_spec.rb file. these specs demonstrate the problem from both a functional standpoint and from the perspective of the internals, where the problem is caused.

      the strange thing is, it's a line in ActiveModel::Errors, line # 223, that causes this. that line is:

      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
      [attributes].flatten.each do |attribute|
      

      `

      I'm baffled by this - but when you grab a reference to the model's #attributes and then stuff it into an array, flatten it, and iterate it (even if the iteration does nothing), then the model's #changes concerning the array attribute are destroyed.

      i've outlined this scenario in one of the specs, directly, so you can see what's happening. unfortunately i wasn't able to figure out why this is happening, so i couldn't fix it. i'll continue to look at this when i have time, but i wanted to get the failing specs pushed up so that someone else can look at it if they have a chance.

      one other note: this branch includes the fixes i submitted for MONGOID-1044. not sure if that matters, just wanted to let you know.

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

              Created:
              Updated:
              Resolved: