Mongoid not caching custom field objects?

XMLWordPrintableJSON

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

      When using fields with a custom serialization class, Mongoid doesn't seem to cache the object we're assigning, and instead it's mongoizing/demongoizing the value each time it's accessed:

      class Document
        include Mongoid::Document
      
        field :foo, type: Foo
      end
      
      doc = Document.new
      doc.foo = Foo.new
      doc.foo === doc.foo # => false
      

      Note: all built-in field types do not seem to behave this way, and calling doc.foo === doc.foo on them returns true.

      Not sure if this is an expected behavior, but it would be cool if it was mentioned somewhere in the docs.

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

              Created:
              Updated:
              Resolved: