How to dynamically set table_name of model object without concurrency issues?

Hello all,

I'm trying to figure out a good way to dynamically set the table_name of an ActiveRecord model object.

I've got a legacy db with multiple tables which hold the same type of data. The tables are laid out as DATA1000 through DATA9999.

My app needs to allow the user to select a number 1000 through 9999 and then use that selection in order to determine the appropriate table to query.

I have a single ActiveRecord object called DataX which I'd like to use to access all of the above tables.

What I've been doing is to call DataX.set_table_name for every search depending on the users selection to get the data from the right table.

This is not going to work in a multi-user env as set_table_name is a class method and I'd be resetting the table name for all users, all sessions.

Does anyone have any other suggestions for dynamically assigning a new table name to an instance of an ActiveRecord that is scoped at the user session level?

Thanks,

Allen

Make DataX abstract and dynamically create subclasses as needed ? It's not pretty but given that (right now) a single instance (mongrel process, fastcgi listener etc..) of rails only processes one request at a time you could probably get away with calling set_table_name on DataX

Fred