def as_json(options = {})
options = {} if options.nil?
result = {}
properties_to_serialize(options).each do |property|
property_name = property.name
value = __send__(property_name)
result[property_name] = value.kind_of?(DataMapper::Model) ? value.name : value
end
Array(options[:methods]).each do |method|
next unless respond_to?(method)
result[method] = __send__(method)
end
if options[:relationships]
options[:relationships].each do |relationship_name, opts|
if respond_to?(relationship_name)
result[relationship_name] = __send__(relationship_name).to_json(opts.merge(:to_json => false))
end
end
end
result
end