Jump to content

Active record pattern

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wwwwolf (talk | contribs) at 19:40, 11 October 2005 (Created). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Active Record is a design pattern frequently found in enterprise applications.

Active Record takes the obvious approach to taking the data from database. A row in a database table or view is wrapped into a class. When object is created, a new row will be added to database when it's saved. When an object is loaded, it gets its information from the database, when it's updated, the row in the database gets updated. The wrapper class implements getters and setters for each column in the table or view.

One of the widely-used implementations is the Active Record implementation found in Ruby on Rails. For example,

a = Part.new
a.name = "Sample part"
a.price = 123.45
a.save

will create a new row in the database, and

a = Part.find(:first, :conditions => ['name = ?', widgetname])

will find the appropriate item from the database.