Active record pattern

From Wikipedia:

In software engineering, the active record pattern is an architectural pattern found in software that stores in-memory object data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture.[1] 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 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 (ORM). Typically, foreign key relationships will be exposed as an object instance of the appropriate type via a property.

PHP ActiveRecord is one open-source library designed to fulfill the active record pattern.[2]

Several open-source PHP frameworks also bundle their own ORM implementing the active record pattern. Most implementations support relationships, behaviors, validation, serialization and support for multiple data sources.

  • Boiler, an MVC framework for PHP, contains a set of tools for auto-generation of active record models.[3] The project, designed for data-centered projects, aims to automate as much of the development process as possible,[4] using Apache Ant. Although a new addition to Open Source market,[5] the project is already in use in many live applications, both commercially and open. The framework currently only supports MySQL though the developers have reported some commercial work in Postgres.
  • Cygnite PHP Framework‘s default database layer implements Active Record pattern which closely resemble with Ruby on Rails.[6]
  • Laravel contains an ORM called ‘Eloquent’ which implements the active record pattern, closely resembling that of Ruby on Rails [7]
  • CakePHP‘s ORM implements the active record pattern,[8] but as of version 2.x queries return arrays of data, with levels of related data as required. Version 3.0 uses objects.
  • Lithium‘s ORM implements active record.
  • Symfony‘s default database layer and ORM “Doctrine” does not implement active record but rather a data mapper approach.
  • CodeIgniter has a query builder it calls “ActiveRecord”, but which does not implement the Active Record pattern. Instead, it implements what the user guide refers to as a modified version of the pattern. The Active Record functionality in CodeIgniter can be achieved by using either CodeIgniter DataMapper library or CodeIgniter Gas ORM library.
  • Yii‘s ORM also implements the active record pattern.[9]
  • Propel also implements the active record pattern.[10]
  • Paris is A lightweight Active Record implementation for PHP5, built on top of Idiorm.[11]

4 thoughts on “Active record pattern”

  1. I not to mention my guys have been reading the best information and facts on your site and then the sudden came up with a terrible feeling I had not expressed respect to the website owner for those secrets. My guys were absolutely thrilled to read all of them and have pretty much been taking advantage of them. Appreciate your turning out to be indeed helpful as well as for making a decision on this kind of incredible ideas most people are really wanting to learn about. My honest apologies for not saying thanks to you earlier.

  2. I discovered your weblog site on google and check just a few of your early posts. Proceed to keep up the very good operate. I simply further up your RSS feed to my MSN News Reader. Seeking ahead to reading more from you afterward!…

  3. Hey there just wanted to give you a quick heads up and let you know a few of the images aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same results.

Leave a Reply

Your email address will not be published. Required fields are marked *