22
33Active Record connects classes to relational database tables to establish an
44almost zero-configuration persistence layer for applications. The library
5- provides a base class that, when subclassed, sets up a mapping between the new
6- class and an existing table in the database. In the context of an application,
7- these classes are commonly referred to as *models*. Models can also be
8- connected to other models; this is done by defining *associations*.
5+ provides a base class, and subclassing an application specific version of
6+ this base class sets up a mapping between the new class and an existing
7+ table in the database. In the context of an application, these classes are
8+ commonly referred to as *models*. Models can also be connected to other
9+ models; this is done by defining *associations*.
910
1011Active Record relies heavily on naming in that it uses class and association
1112names to establish mappings between respective database tables and foreign key
@@ -17,7 +18,7 @@ A short rundown of some of the major features:
1718
1819* Automated mapping between classes and tables, attributes and columns.
1920
20- class Product < ActiveRecord::Base
21+ class Product < ApplicationRecord
2122 end
2223
2324 {Learn more}[link:classes/ActiveRecord/Base.html]
@@ -37,7 +38,7 @@ This would also define the following accessors: `Product#name` and
3738
3839* Associations between objects defined by simple class methods.
3940
40- class Firm < ActiveRecord::Base
41+ class Firm < ApplicationRecord
4142 has_many :clients
4243 has_one :account
4344 belongs_to :conglomerate
@@ -48,7 +49,7 @@ This would also define the following accessors: `Product#name` and
4849
4950* Aggregations of value objects.
5051
51- class Account < ActiveRecord::Base
52+ class Account < ApplicationRecord
5253 composed_of :balance, class_name: 'Money',
5354 mapping: %w(balance amount)
5455 composed_of :address,
@@ -60,7 +61,7 @@ This would also define the following accessors: `Product#name` and
6061
6162* Validation rules that can differ for new or existing objects.
6263
63- class Account < ActiveRecord::Base
64+ class Account < ApplicationRecord
6465 validates :subdomain, :name, :email_address, :password, presence: true
6566 validates :subdomain, uniqueness: true
6667 validates :terms_of_service, acceptance: true, on: :create
@@ -72,7 +73,7 @@ This would also define the following accessors: `Product#name` and
7273
7374* Callbacks available for the entire life cycle (instantiation, saving, destroying, validating, etc.).
7475
75- class Person < ActiveRecord::Base
76+ class Person < ApplicationRecord
7677 before_destroy :invalidate_payment_plan
7778 # the `invalidate_payment_plan` method gets called just before Person#destroy
7879 end
@@ -82,7 +83,7 @@ This would also define the following accessors: `Product#name` and
8283
8384* Inheritance hierarchies.
8485
85- class Company < ActiveRecord::Base ; end
86+ class Company < ApplicationRecord ; end
8687 class Firm < Company; end
8788 class Client < Company; end
8889 class PriorityClient < Client; end
0 commit comments