mongoid/mongoid — Issue #1515: Mongoid try to serialize values of complex criteria for customs serialized fields
Author: lexer
Created: 2011-12-21 06:30:39+00:00
State: open

I've create following custom type

class LatLng
include Mongoid::Fields::Serializable

def deserialize(object)
{ :lat => object[1], :lng => object[0] }.with_indifferent_access
end

def serialize(object)
latlng = object.with_indifferent_access
[ latlng[:lng], latlng[:lat] ]
end
end

Running of this query

field :from_latlng, type: LatLng

doc.where(:from_latlng => {"$nearSphere" => [lng, lat], "$maxDistance" => radius / EARTH_RADIUS}) will cause exception due to it tries to serialize params from complex criteria hash using my custom type.