This post originated from an RSS feed registered with Ruby Buzz
by Rick DeNatale.
Original Post: Book Review: Pro Active Record
Feed Title: Talk Like A Duck
Feed URL: http://talklikeaduck.denhaven2.com/articles.atom
Feed Description: Musings on Ruby, Rails, and other topics by an experienced object technologist.
I've been meaning to write a review of the recently published Apress book "Pro Active Record" by Kevin Marshall, Chad Pytel, and Jon Yurek for a while now. I have to admit that I was prompted to sit down and actually do it after reading Josh Susser's recent review of the same book.
While I generally agree with Josh's assessment, We do differ a bit on which audience the book best serves.
The goal of the book is to cover Active Record in depth, outside of the context of Rails. The result, as I see it, is a book which is useful to intermediate to advanced users of Active Record, those who want to dig in to understanding the implementation and perhaps extending it.
My own reading of the book gave me the impetus to explore the code of Active Record to the extent where I felt comfortable submitting contributions to Rails. Since reading the book, I've written and submitted two active record patches to the Rails Trac. The first fixed an oversight which made the schema.db file dumped for MySQL tables with non-standard primary keys to lack those primary key declarations, and the second is an enhancement which allows the :joins option of methods like find and count in ActiveRecord::Base to take values like the :include option as an alternative to a sql joins clause string. Both have made it into rails edge!
Pro Active Record for Beginners?
While I suppose that you could learn Active Record just from this book, I personally think that Agile Web Development with Rails (2nd ed) does a better job, and makes a better reference for everyday use of Active Record. While not entirely devoted to Active Record, AWDWR devotes four chapters and 131 pages to it in the "Rails in Depth" section of the book, in addition to coverage of AR in the tutorial section. In contrast, "Pro Active Record" comprises 8 chapters in 214 pages, plus a 52 page Appendix which is pretty much derived from the RDoc generated from the Active Record source code.
Shortly after I bought the book, I was working on an issue with some active record validation callbacks on one of my projects. Since "Pro Active Record" was at hand I turned to it. Although they have good coverage of the topic in Chapter 4, "Core Features of Active Record", the five pages of text description in PAR just doesn't make it as clear when particular callbacks will be called as the single chart on page 372 of the "Object Life Cycle" chapter in AWDWR.
While some newcomers to active record who are using, say Camping, might welcome the "Rails-free" presentation of PAR, sometimes I get the impression that studiously eschewing Rails in this book hampers it just a bit. There sems to be a little too much repetition of things that Rails does for you, like ActiveRecord::Base.connect(...)
Digging In
That said, I do really like the book. The chapter on dealing with legacy databases is quite useful, and I'd recommend it.
The best part of the book was the section on extending AR. It gives a good introduction to the way AR works, it got me started actually reading the AR code in edge rails. It also gives some good coverage of Ruby metaprogramming, particularly in the context of AR and Rails
Summary
So all in all, I recommend the book, although I would recommend newcomers to start with Agile Web Development with Rails (2nd ed) even if they are using AR outside of rails.
Those who are, or want to be, a little further along in their exploration, exploitation, and extension of Active Record will find it to be a valuable addition to their book shelf, just as I did.