0
module ActiveRecord #:nodoc:
0
- # Builds an XML document to represent the model. Some configuration is
0
- # available through +options+, however more complicated cases should
0
- # override ActiveRecord's to_xml.
0
+ # Builds an XML document to represent the model. Some configuration is
0
+ # available through +options+. However more complicated cases should
0
+ # override ActiveRecord's to_xml method.
0
# By default the generated XML document will include the processing
0
- # instruction and all
object's attributes. For example:
0
+ # instruction and all
the object's attributes. For example:
0
# <?xml version="1.0" encoding="UTF-8"?>
0
@@ -23,10 +23,10 @@ module ActiveRecord #:nodoc:
0
# This behavior can be controlled with :only, :except,
0
- # :skip_instruct, :skip_types and :dasherize.
The :only and
0
+ # :skip_instruct, :skip_types and :dasherize.
The :only and
0
# :except options are the same as for the #attributes method.
0
# The default is to dasherize all column names, to disable this,
0
- # set :dasherize to false.
To not have the column type included
0
+ # set :dasherize to false.
To not have the column type included
0
# in the XML output, set :skip_types to true.
0
@@ -68,6 +68,36 @@ module ActiveRecord #:nodoc:
0
+ # To include deeper levels of associations pass a hash like this:
0
+ # firm.to_xml :include => {:account => {}, :clients => {:include => :address}}
0
+ # <?xml version="1.0" encoding="UTF-8"?>
0
+ # <id type="integer">1</id>
0
+ # <rating type="integer">1</rating>
0
+ # <name>37signals</name>
0
+ # <clients type="array">
0
+ # <rating type="integer">1</rating>
0
+ # <rating type="integer">1</rating>
0
+ # <name>Microsoft</name>
0
+ # <id type="integer">1</id>
0
+ # <credit-limit type="integer">50</credit-limit>
0
# To include any methods on the object(s) being called use :methods
0
# firm.to_xml :methods => [ :calculated_earnings, :real_earnings ]
0
@@ -78,7 +108,7 @@ module ActiveRecord #:nodoc:
0
# <real-earnings>5</real-earnings>
0
- # To call any Proc
's on the object(s) use :procs. The Proc's
0
+ # To call any Proc
s on the object(s) use :procs. The Procs
0
# are passed a modified version of the options hash that was
0
@@ -90,7 +120,7 @@ module ActiveRecord #:nodoc:
0
- # Alternatively, you can
also just yield the builder object as part of the to_xml call:
0
+ # Alternatively, you can
yield the builder object as part of the to_xml call:
0
@@ -108,7 +138,7 @@ module ActiveRecord #:nodoc:
0
# You can override the to_xml method in your ActiveRecord::Base
0
- # subclasses if you need to.
The general form of doing this is0
+ # subclasses if you need to.
The general form of doing this is:0
# class IHaveMyOwnXML < ActiveRecord::Base
0
# def to_xml(options = {})
0
@@ -155,13 +185,6 @@ module ActiveRecord #:nodoc:
0
!options.has_key?(:dasherize) || options[:dasherize]
0
- # To replicate the behavior in ActiveRecord#attributes,
0
- # :except takes precedence over :only. If :only is not set
0
- # for a N level model but is set for the N+1 level models,
0
- # then because :except is set to a default value, the second
0
- # level model can have both :except and :only set. So if
0
- # :only is set, always delete :except.
0
def serializable_attributes
0
serializable_attribute_names.collect { |name| Attribute.new(name, @record) }
0
@@ -251,7 +274,7 @@ module ActiveRecord #:nodoc:
0
# There is a significant speed improvement if the value
0
# does not need to be escaped, as #tag! escapes all values
0
- # to ensure that valid XML is generated.
For known binary
0
+ # to ensure that valid XML is generated.
For known binary
0
# values, it is at least an order of magnitude faster to
0
# Base64 encode binary values and directly put them in the
0
# output XML than to pass the original value or the Base64