Legacy Woes
December 19th, 2008
I've been working with a legacy database for a while, and I'm getting tired of writing methods to do all of the nice hooks that ActiveRecord comes with. Hooks like automatically setting created_at on a save. I did what any self respecting lazy programmer would do, and created a new gem, LegacyWoes. If you fix some legacy issues I'd love to talk or take a patch.
Legacy Polymorphic Associations
December 10th, 2008
Did I mention I hate legacy databases.
I'm working on a legacy project that uses a polymophic associations where the type column is lower case. The thing that sucks is I can't change the database because I still have an untested Java side that we don't want to change. So here comes the solution, and maybe some flames.
ActiveRecord::AttributeMethods#read_attribute is called on the type field, which we will call foo, because it isn't called type in our database. So in our model we have this:
#Disclaimer
def read_attribute(attr_name)
if attr_name == 'foo'
#code to change to accepted type column values
foo.camelize
else
super
end
end