The equivalent Ruby
type is generally :binary, :string, or an I/O stream.
As you can see, data types and their mappings are often unique to each database system
and, therefore, are implemented in each Active Record adapter. We recommend you spend
a little time in your specific adapter??™s source code getting familiar with how it handles data
type conversions.
Importing and Exporting
While the primary storage mechanism for Active Record objects is a relational database, there
are several reasons why you might export the data stored in Active Record objects to other formats.
Whether for integration with other systems, reporting, or testing purposes, converting
Active Record objects into other formats is, thankfully, easy.
CHAPTER 7 ?– WORKING WITH LEGACY SCHEMA 181
Exporting XML
XML has emerged as a standard data interchange format, and Active Record includes, on every
object, a to_xml method that allows you to get an XML representation of the Active Record object.
?– Note While the to_xml method does take a hash of configuration options, it is generally recommended
that for more complex XML generation you should use Active Support??™s Builder class and either override
to_xml or provide a custom method with a different name.
Pages:
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414