Monday, February 15, 2010

About ORM (Object Relation Mapping)

Accessing database using a layer of classes is called ORM. The rest of the application uses these classes and their objects. It never allow directly interacting with database.

1. ORM libraries map database tables to classes. If a database has a table users(plural).Our program will have a class named user(singular) stored in model folder,

2. Rows in this table correspond to objects of the class—a particular user is represented as an object of class user.
3. By using this object's attributes we can set and get the individual columns.

So an ORM layer maps tables to classes, rows to objects and columns to attributes of that object(methods).


Class methods are used to perform table-level operations.
Instance methods are used to perform operations on the individual rows.

It is all taken care by ActiveRecord class.

1 comment:

Jonno said...

Sounds like you're describing Active Record pattern: http://en.wikipedia.org/wiki/Active_record_pattern