This term comes from the idea that if it walks like a duck, and quacks like
a duck, it must be a duck. You can read more about duck typing at http://en.wikipedia.org/wiki/
Duck_typing.
Overriding the Assumptions
While staying true to the Active Record way of doing things can free you up to worry about
other things during application development, obviously your application may have some
constraints that require you to override some of the assumptions that Active Record is making,
particularly if you are working with a legacy database.
CHAPTER 1 ?– INTRODUCING ACTIVE RECORD 20
If you want table names to be singular instead of plural, you can set the configuration
parameter pluralize_table_names:
ActiveRecord::Base.pluralize_table_names = false
If, instead, you need to override a table name completely, you specify this in the Active Record
class itself. For instance, if our Accounts class should persist to a table named AccountBean, we
would specify the Account class as follows:
class Account < ActiveRecord::Base
set_table_name "AccountBean"
end
Additionally, if your primary key column is not named simply id, you can override this
from within the class definition as well:
class Account < ActiveRecord::Base
set_primary_key "accountId"
end
If you want to use a primary key other than an automatically incremented integer, you
must set the value of the primary key yourself, and you must still use the id attribute to do so.
Pages:
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93