Blog posts tagged "oo"

Rails, Data Models, and find_by_sql

March 24th, 2005

Did a little more hacking on Recipes on Rails yesterday. Haven’t decided if I’m doing something wrong, or if ActiveRecord sacrifices a lot of flexibility in the quest for rapid development. I find myself using find_by_sql heavily, which seems wrong. Could be a metaphor clash.

Mental Models and Metaphors

With Enterprise we used a heavily sub-classed DB::DataObject, also an Active Record implementation but with a different metaphor. It doesn’t have AR’s awesome, and brain dead simple declarative association syntax, instead it takes a method oriented approach to query building which allows you to build up a domain model hiearchy where query logic accretes via polymorphism.

The simplest possible example of this is our use of a domainId key in Enterprise which is used to silo and segregate our data (development was primarily targeting ASP deployment). Any DAO which descends from GS::DataObject will automatically insert domainId into the query. In general it meant we could right powerful find methods that were actually very thin wrappers of a parent find, just permutating the query slightly with the addition of a few add conditions (e.g. wheres, sub-queries, left outer joins, whatever).


Still very much learning Rails (and Ruby), so take it all with a grain of salt. Maybe there is room for a mix-in somewhere that would refactor away the find_by_sql usage.

The Desperate PHP Hacker

Much of the current evangelism (of which DHH and 37sigs are an amazing, untiring source) seems to have targetted the Java developer community (or perhaps they’re just the most touchy?). Seems like there is a need for a ‘Rails Eye for the PHP Guy’ kind of series. I wonder if my PHP style is too idiosyncratic.

Tagged: Uncategorized , , , , , ,