Active Record
An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.
—Martin Fowler2
Like the transaction script pattern, active record supports cases where the business logic is simple. Here, however, the business logic may operate on more complex data structures. For example, instead of flat records, we can have more complicated object trees and hierarchies, as shown in Figure 5-4.
![]() |
2 Fowler, M. (2002). Patterns of Enterprise Application Architecture. Boston: Addison-Wesley.
Figure 5-4. A more complicated data model with one-to-many and many-to-many relationships
Operating on such data structures via a simple transaction script would result in lots of repetitive code. The mapping of the data to an in-memory representation would be duplicated all over.