Difference between Active Record and DAO?

helpermethod picture helpermethod · Jul 10, 2011 · Viewed 9.2k times · Source

What's the difference between a Data Access Object and Active Record? They seem to be quite the same, as both built a layer between the application and persistence layer, and abstract away direct database access using SQL queries.

Answer

mattmc3 picture mattmc3 · Jul 10, 2011

Data Access Object (DAO) refers to an object in your data layer responsible for persisting a separate entity in your domain. Active Record is a specific method of doing a DAO where the class containing the values of a single row from a table is also responsible for queries, updates, inserts, and deletes to that table. The Active Record design pattern means your object has a one-to-one mapping with a table in your database.