Active record pattern: Difference between revisions

Content deleted Content added
Blanket opinion statement, not how this should be written. Undid revision 997726488 by 90.174.3.116 (talk)
Tags: Undo Reverted
Undid revision 1004554818 by Nicereddy (talk) These are published references. If these were opinions we may also need to remove Martin Fowler opinions
Tags: Undo Reverted
Line 1:
In [[software engineering]], the '''active record pattern''' is an [[Architectural pattern (computer science)|architectural pattern]] (currently regarded as an [[anti-pattern]])<ref>[https://www.oreilly.com/library/view/sql-antipatterns/9781680500073/f_0159.html Antipattern: The Model Is an Active Record]</ref><ref>[https://www.mehdi-khalili.com/orm-anti-patterns-part-1-active-record ORM anti-patterns - Part 1: Active Record]</ref><ref>[http://misko.hevery.com/2009/05/05/the-problem-with-active-record/ The problem with Active Record]</ref><ref>[https://softwareengineering.stackexchange.com/questions/119352/does-the-activerecord-pattern-follow-encourage-the-solid-design-principles Does the ActiveRecord pattern follow/encourage the SOLID design principles?]</ref> found in software that stores in-memory object data in [[relational database]]s. It was named by [[Martin Fowler (software engineer)|Martin Fowler]] in his 2003 book ''Patterns of Enterprise Application Architecture''.<ref>{{cite book |last=Fowler |first=Martin |title=Patterns of enterprise application architecture |publisher=Addison-Wesley |year=2003 |isbn=978-0-321-12742-6 |url=https://books.google.com/books?id=FyWZt5DdvFkC&q=active+record&pg=PT187 }}</ref> The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table.
 
The active record pattern is an approach to accessing data in a [[database]]. A [[database table]] or [[View (database)|view]] is wrapped into a [[class (computer science)|class]]. Thus, an [[object (computer science)|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]] [[Method (computer programming)|methods]] or properties for each column in the table or view.