Welcome Guest, Not a member yet? Register   Sign In
Object Relational Mapping (ORM) vs. Active Records
#1

[eluser]skaterdav85[/eluser]
What is the difference between using an ORM framework and the Active Record database pattern? I heard some of the other php frameworks have ORM built into them but I don't see how that is different from the Active Record database pattern.
#2

[eluser]n0xie[/eluser]
There are 2 things to keep in mind. There is the ORM and AR design pattern and then there is the way it is implemented.

Simply put: Active Record, properly defined, is a design pattern where an object is represented as a record on a table in a relational database.

Data Mapper is very similar to Active Record but with one major design difference: The representation of an object is not necessarily a record from a table in a relational database. Hence, the keyword "Mapper" instead of "Record". Data Mapper can implement Active Record albeit without the efficiencies that come with the assumption of the "one object - one record" constraint.

This feature of the design is important when you start to consider data stores other than relational databases (e.g. external data stores accessed through REST, file based data storage or schema free databases). The rise of NoSQL, web applications and web services has fueled the need for more flexibility in the ORM layer.

In CodeIgniter the Active Record Class is actually a SQL wrapper class, which simulates the Active Record Database pattern. It replaces the need to write SQL statements by using 'object notation'. This 'simulates' the Active Record behaviour and is at the heart of much of the confusion for beginners: all the different ORM implementations for CodeIgniter that are available are in fact actually true Active Record implementations (i.e. they map an objoct to a database record).

To clarify: ORM maps an object to a data 'source' (this does not have to be database). One of the implementations is the Active Record pattern (which maps a table row to an object).

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB