Create an Active Record object.
2. Manipulate or access the attributes of the object.
3. Save the attributes as a record in the database.
As mentioned previously, updating data can be done using the previous steps or with
a special update call shown in the following example:
Account.update(1, "Username = Kevin")
Deleting data from a database, on the other hand, is a little bit of a special situation, since
you often want your database records to exist long after your Active Record objects have been
destroyed or gone out of scope. If we tied the deletion of data from the database to the life cycle
of our objects, every time our code was finished executing, our objects would be removed from
memory and our data deleted from our database. That would be a very bad thing. Therefore,
deleting data is done by special destroy or delete statements??”not by simply removing the object
from memory. The following example shows one way of deleting the record with a primary
key of 1:
Account.delete(1)
CHAPTER 1 ?– INTRODUCING ACTIVE RECORD 5
If it seems like we are glossing over the details of all this, don??™t worry; we??™ll break down the
specifics of each of these steps throughout different parts of this book.
Pages:
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59