Prev | Current Page 79 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


Table 3-1 lists some examples of assumptions Active Record would make based on the
guidelines we??™ve just outlined.
CHAPTER 1 ?–  INTRODUCING ACTIVE RECORD 19
Table 3-1. Examples of Active Record Table Pluralization
Class Name Table Name
Account accounts
Person people
UserImage user_images
Address addresses
Currency currencies
Mouse mice
As you can see from the Table 3-1, Active Record is intelligent about pluralizing the class
names. In addition, Active Record also assumes that each table has an automatically incremented
integer primary key column named id.
When an Active Record class is instantiated and any data is accessed within the class,
Active Record reads the columns of the table and maps these to the class??™s attributes. While
there aren??™t formal conventions for the naming of columns, since Active Record only creates
an attribute in the Active Record class that matches the name of the column, many of the
Ruby and Rails naming conventions are seen in a typical Active Record table, including the
liberal doses of underscores.


Pages:
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91