Active record pattern

In computer science, the active record pattern is a design pattern frequently found in software that stores its data in relational databases. It was named by Martin Fowler in his book "Patterns of Enterprise Application Architecture".

Active record is an approach to accessing data in a database. A database table or view is wrapped into a class, thus an object instance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save. Any object loaded gets its information from the database; when an object is updated, the corresponding row in the table is also updated. The wrapper class implements accessor methods or properties for each column in the table or view.

This pattern is commonly used by object persistence tools, and in object-relational mapping. Typically foreign key relationships will be exposed as an object instance of the appropriate type via a property.

Implementations of Active Record can be found in various frameworks for many programming environments. For example, if in a database there is a table parts with columns name (string type) and price (number type), and the Active Record pattern is implemented in the class Part, the following pseudo-code:

part = new Part() part.name = "Sample part" part.price = 123.45 part.save()

will create a new row in the parts table with the given values, and is roughly equivalent to the SQL command

INSERT INTO parts (name, price) VALUES ('Sample part', 123.45);

Conversely, the class can be used to query the database:

b = Part.find_first("name", "gearbox")

This will create a new Part object based on the first matching row from the parts table whose name column has the value "gearbox". The SQL command used would be

SELECT * FROM parts WHERE name = 'gearbox' LIMIT 1;

See also

*Object-relational mapping


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Active Record (Patron De Conception) — En génie logiciel, le patron de conception (design pattern) active record (enregistrement actif en anglais) est une approche pour lire les données d une base de données. Les attributs d une table ou d une vue sont encapsulés dans une classe.… …   Wikipédia en Français

  • Active record — (patron de conception) En génie logiciel, le patron de conception (design pattern) active record (enregistrement actif en anglais) est une approche pour lire les données d une base de données. Les attributs d une table ou d une vue sont… …   Wikipédia en Français

  • Active record (motif de conception) — Active record (patron de conception) En génie logiciel, le patron de conception (design pattern) active record (enregistrement actif en anglais) est une approche pour lire les données d une base de données. Les attributs d une table ou d une vue… …   Wikipédia en Français

  • Active record (patron de conception) — En génie logiciel, le patron de conception (design pattern) active record (enregistrement actif en anglais) est une approche pour lire les données d une base de données. Les attributs d une table ou d une vue sont encapsulés dans une classe.… …   Wikipédia en Français

  • Pattern Is Movement — Infobox musical artist Name = Pattern is movement Img capt = Img size = Landscape = Background = group or band Alias = Origin = Philadelphia, Pennsylvania, United States Genre = Indie rock Years active = 2001 ndash;present Label = NFI, Hometapes… …   Wikipedia

  • Semi-active radar homing — Semi active radar homing, or SARH, is a common type of missile guidance system, perhaps the most common type for longer range air to air and surface to air missile systems. The name refers to the fact that the missile itself is only a passive… …   Wikipedia

  • Gramophone record — A 12 inch (30 cm) 33⅓ rpm record (left), a 7 inch 45 rpm record (right), and a CD (above) A gramophone record, commonly known as a phonograph record (in American English), vinyl record (in reference to vinyl, the material most commonly used after …   Wikipedia

  • Top of the Pops (record series) — Infobox musical artist Name = Top of the Pops Img capt = Img size = Genre = Pop music Years active = 1968–1985 Label = HallmarkInfobox musical artist Name = Top of the Poppers Img capt = Img size = Landscape = yes Background = group or band Alias …   Wikipedia

  • ActiveRecord — * Active record pattern is a computer science concept, seen in enterprise application design. * ActiveRecord (Rails) is the active record pattern implementation for Ruby on Rails. * ActiveRecord (Castle) is the active record pattern… …   Wikipedia

  • Comparison of web application frameworks — This is a comparison of notable web application frameworks. Contents 1 General 1.1 Perl 1.2 PHP 1.3 Java 1.4 Python …   Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.