The idea of ββthe model is to complete the logical collection of data inside your code.
The idea behind DataMapper is to associate this dataset at the application level with how you store it.
For many ActiveRecord implementations, the framework does not provide this separation of intent, and this can lead to problems. For example, the BlogPost model can wrap basic blog information, such as
- title
- Author
- Body
- date_posted
But you might also want it to have something like:
- number_of_reads
- number_of_likes
Now you can save all this data in one MySQL table to start, but as your blog grows and you become super famous, you will find that your statistics capture many hits and you want to move it to a separate database server.
How could you transfer these fields of BlogPost objects to another data store without changing the application code?
Using DataMapper, you can change the way the object is saved to the database and the way it is loaded from the database. This allows you to customize the storage mechanism without having to change the actual set of information your application relies on.
Justin demaris
source share