Set_table_name woes, fragmented domain class

Hi all,

I’m running Rails on top of a Mongrel cluster. I have several model
classes that are going to have so many records it is not feasible to
keep them all in the same table. So I’ve split out the records into
many different tables, each with its own suffix which corresponds to
the id of the model to which all records in that particular table
belong.

For example, if I have a Domain AR object with an id of 20, all
DomainURL objects that :belong_to that particular Domain object are
stored in table domain_urls_20.

This necessitates a call to set_table_name before the DomainURL
objects are fetched, like so:

DomainURL.set_table_name “domain_urls_” + domain.id

However, when I go into production mode, I get mismatched table and
column names on my find’s. I am assuming this is caused by
ActiveRecord caching the domain model so that set_table_name is
rendered ineffective when it goes to fetch a record. However, I’m not
quite sure if this is the case.

If anyone could shed some light here, or possibly suggest an
alternative method of accomplishing my objective, I’m all ears.

Thanks,

Michael J. I. Jackson
[email protected]

Michael J. I. Jackson wrote:

This necessitates a call to set_table_name before the DomainURL
objects are fetched, like so:

DomainURL.set_table_name “domain_urls_” + domain.id

However, when I go into production mode, I get mismatched table and
column names on my find’s. I am assuming this is caused by
ActiveRecord caching the domain model so that set_table_name is
rendered ineffective when it goes to fetch a record. However, I’m not
quite sure if this is the case.

Perhaps your problem is caching of table names by the urls
association. You could clear the cache using something like

class Domain
has_many :urls, :class_name => ‘DomainURL’

def set_url_table
self.class.reflect_on_association(:urls).instance_eval do
@table_name = @quoted_table_name = nil
end
DomainURL.set_table_name “domain_urls_” + id
end
end

domain = Domain.find(…)
domain.set_url_table
urls = domain.urls


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com