This module provides the extra behaviour for including relations in JSON and XML serialization.
Gets the document as a serializable hash, used by ActiveModel's JSON serializer.
@example Get the serializable hash.
document.serializable_hash
@example Get the serializable hash with options.
document.serializable_hash(:include => :addresses)
@param [ Hash ] options The options to pass.
@option options [ Symbol ] :include What relations to include. @option options [ Symbol ] :only Limit the fields to only these. @option options [ Symbol ] :except Dont include these fields. @option options [ Symbol ] :methods What methods to include.
@return [ Hash ] The document, ready to be serialized.
@since 2.0.0.rc.6
# File lib/mongoid/serialization.rb, line 27 def serializable_hash(options = nil) options ||= {} attrs = {} names = field_names(options) method_names = Array.wrap(options[:methods]).map do |name| name.to_s if respond_to?(name) end.compact (names + method_names).each do |name| without_autobuild do serialize_attribute(attrs, name, names, options) end end serialize_relations(attrs, options) if options[:include] attrs end
Generated with the Darkfish Rdoc Generator 2.