Jeff Pollard
2010-Nov-29 23:51 UTC
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.