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

Marshaling documents

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

      Mongoid has some issues with Ruby's Marshaling of document object instances. One issue we've run into hard is that when a model uses association extensions and those extensions have been accessed in the lifecycle of the instance, then Marshal.dump fails with the document instance.

      require 'rubygems'
      require 'mongoid'

      class Product
      include Mongoid::Document
      embeds_many :images do
      def active
      @target.select(&:active?)
      end
      end
      end

      class Image
      include Mongoid::Document
      embedded_in :product, :inverse_of => :images
      def active?
      true
      end
      end

      p = Product.new

      Marshal.dump(p) #=> "\004\bo:\fProduct\n:\016@accessed{\000:\020@attributes{\006\"\b_ido:\023BSON::ObjectId\006:\n@data[\021iRi'i*iRi\001\324i\001\354i\001\236i\030i\001\261i\000i\000i\006:\023@modifications{\000:\034@previous_modifications{\000:\020@new_recordT"

      p.images.build

      Marshal.dump(p) #=> TypeError: can't dump anonymous class #<Module:0x103511860>

            Assignee:
            Unassigned Unassigned
            Reporter:
            cgriego Chris Griego
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: