Prev | Current Page 402 | Next

Brad Ediger

"Advanced Rails"

frameworks in config/environment.rb:
config.frameworks -= [ :active_record ]
272 | Chapter 9: Incorporating and Extending Rails
DataMapper
The DataMapper library (http://www.datamapper.org/) is based on Martin Fowler??™s
Data Mapper pattern, which is similar to Active Record but with less coupling.
Active Record??™s chief structural weakness is that it ties the database schema to the
object model. We see this happen in Rails when using ActiveRecord. Every structural
change we want to make to the objects must be reflected in the database at the
same time.
The Data Mapper pattern provides a better balance when the object model and database
need to evolve separately. The drawback is that there will be some duplication.
Because of the additional layer of indirection, DataMapper cannot infer your object??™s
structure from the database like ActiveRecord can. This is the necessary price of
flexibility.
DataMapper confers several other advantages over ActiveRecord:
??? DataMapper includes an implementation of the Identity Map pattern, which
ensures that each database record is loaded only once. ActiveRecord will happily
allow a record to be loaded many times, which can potentially cause conflicts
when one becomes stale.
??? Empirically, DataMapper is faster than ActiveRecord. The code is also smaller
and less complicated. This can be good or bad, depending on whether you need
ActiveRecord??™s more advanced features.


Pages:
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414