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 mjijackson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2009-Mar-19 04:25 UTC
Re: set_table_name woes, fragmented domain class
Michael J. I. Jackson wrote:> 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.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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---