How to change ActiveRecord's table name during runtime

367 views
Skip to first unread message

György Frivolt

unread,
Mar 31, 2011, 12:02:30 PM3/31/11
to Octopus - Database sharding for ActiveRecord
Hi Mates,

I am returning to this forum. I guess that you maybe have experiences
with the issue I am facing. Probably I will be more specific than I
was last time. I am writing you because I think you have mastered the
ActiveRecord internals, which I do not fully know yet.

I am changing the table_name_prefix during running of a rails
application (might sound weird, but really that's what I want). When
the table_name_prefix changes for the ActiveRecord I reset the table
names (table_name and quoted_table_name) by calling reset_table_name,
and they change.. however I have another issue.

If the table name changes, after calling such a thing like count or a
find the ActiveRecord object still operates with the table, which was
used before.

How can reach to reset an ActiveRecord descendant, so that when the
prefix, suffix, table_name changes it works with the new settings?

My ultimate goal is to do this: http://github.com/fifigyuri/handles_custom_domains

I tried to ask this question on SO,
http://stackoverflow.com/questions/5493846/how-to-change-activerecords-table-name-during-runtime,
with no luck so far.

Maybe this thing I am time to time returning to is a bit freak.
Honestly I also enjoy that I am getting deeper into ActiveRecord and
rails internals.

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages