Finding by subclass of string in activerecord fails under certain situations

Ran in to a problem where we were running to to a lot of these errors when we upgraded to Rails 3.0.3:

NoMethodError: undefined method `visit_Foo’ for #Arel::Visitors::MySQL:0x104d0f4d0

After some digging, it turned out that arel used the obj.class.name to lookup the visitor for obj. In our app, Foo is a subclass of String that we use for tracking URL and domain normalization logic. Using it in activerecord #create works, but finders mostly don’t work. See the Lighthouse case for info:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6023-unable-to-find-by-subclasses-of-string-in-activerecord

I added a patch to #to_s String values before sending them off to arel. Feedback on the patch is greatly appreciated.

Thanks,

Jeff Pollard