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

Deserialization on custom type doesn't work

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

      This concerns 2.4. (happens at least on 2.4.9 & 2.4.11)

      I'm trying to add support for mongoid to the gem money-rails. Here is my fork, and here is where I define the serializers.

      This is the model in my code :

      class SuggestedRate
        include Mongoid::Document
      
        ## Schema
        field :rate, type: Money
      
        #...
      end
      

      And this is what doesn't work as expected

      irb(main):005:0> sr = SuggestedRate.new
      => #<SuggestedRate _id: 4fe1b1659671383699000002, _type: nil, ambassador_detail_id: nil, skill_id: nil, rate: nil>
      irb(main):006:0> sr.rate
      => nil
      irb(main):007:0> sr.rate = Money.new(100)
      => #<Money cents:100 currency:EUR>
      irb(main):008:0> sr.rate
      => {:cents=>100, :currency_iso=>"EUR"}
      irb(main):009:0> 
      

      As you can see, the serialization works like a charm, but the deserialization, on the other end, doesn't seem to do anything but return the field as it is.

      Any idea what I'm doing wrong here ?

      Thanks for your time!

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

              Created:
              Updated:
              Resolved: