Though the whole idea is to represent database records as objects, it??™s important to remember
that they really are two separate things: Ruby objects and database records. As such, you can
(and will) sometimes have your database record in a different state or with a different value than
its corresponding Active Record object and its attributes. This is probably most obvious when
you are dealing with data validations. When a data validation fails during an attempt to save,
your Active Record object attribute will still have the value assigned by your application (which
fails validation), but your database record will not have been updated. We talk more about this
issue, and data validation in detail, in Chapter 4.
From Active Record Objects to Database Records
and Back Again
Even though Active Record objects are really just Ruby objects, when packaged as the Active Record
library, they do go through a number of built-in steps or methods each time they are created,
accessed, updated, or deleted. Whether you are saving new records, updating existing ones, or
simply accessing data with Active Record, there are three general steps to follow:
1.
Pages:
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58