Rails update

It’s that time of year where I get my online orienteering system out of mothballs ready for the next JOK Chasing Sprint. My first task was to update the application to the latest Rails 2.1.2 which proved to be harder than I had anticipated. I’m used to working with enterprise software where it’s a given that you can’t break users’ existing applications.

Running a deprecation script picked up most of the areas I needed to change of which the move from built-in pagination to will_paginate required the most effort/thought. The biggest issue I encountered though was around eager loading of associations. I eventually found a posting which describes how Rails will now only honour include associations if it detects that they are not being used. In my case, a column for the included class was referred to in the conditions but wasn’t qualified by the table name which wasn’t sufficient to cause the eager loading. This then caused the where clause to fail on select. Qualifying the table name was sufficient to get it working again.

In other words. I had to change a statement like:
Example.find :all, :include => [:associated_class], :conditions => ['associated_class_column < 10']
to:
Example.find :all, :include => [:associated_class], :conditions => ['associated_classes.associated_class_column < 10']

Comments are closed.