Forum: Ruby on Rails ActiveRecord and refreshing column info

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8f6770aa18a37c249412a24fb2570bf8?d=identicon&s=25 Ian Whitney (Guest)
on 2006-05-08 21:22
Let's say I want to find out what column names exist in two tables,
table_a and table_b.

One way I've been doing this is using ActiveRecord and the column info
it returns. After establishing a connection for ActiveRecord, I do the
following:

ActiveRecord::Base.set_table_name("table_a")
column_names_a = ActiveRecord::Base.column_names
ActiveRecord::Base.set_table_name("table_b")
column_names_b = ActiveRecord::Base.column_names

The problem I have is that once I set the table_name to 'table_a',
ActiveRecord always returns table_a's column info. I've tried the
following ActiveRecord methods to clear the info in column_names &
neither has worked

ActiveRecord::Base.reset_column_information
ActiveRecord::Base.remove_connection

Even after removing & then restablishing the connection, the
column_names method continues to return table_a's columns.

So I'm obviously on the wrong track here. But I can't find out where I
should be headed. Any ideas?

Thanks!

Versions being used:
Ruby 1.8.4
RoR 1.1
This topic is locked and can not be replied to.