Unfortunately I had to work on some proprietary MSSQL database
building some internal web application. Naturally, I use RoR 1.2.4.
Even I add set_table_name and set_primary_key in Model (RegionalIndex)
of mine it have made SQL requests using regional_indexes as a table
name.
After spending some time I come with the solution witch puzzled me a
bit.
The model is looks as follows:
class Regionalindex < ActiveRecord::Base
set_table_name “RegionalIndex”
set_primary_key “IndexID”
end
and it not works as expected.
When I change it to
class Regionalindex < ActiveRecord::Base
ActiveRecord::Base.set_table_name “RegionalIndex”
ActiveRecord::Base.set_primary_key “IndexID”
End
It would look like this would set the table name and primary key for
ALL models. Actually it appears to set it for subsequent subclasses,
including the one currently being defined if, as you have it, it’s in
the context of a class definition. Here’s an experiment using rails
from svn:
$ script/console
Loading development environment (Rails 1.2.4)
*******************************************************************
* config.breakpoint_server has been deprecated and has no effect.
class A < ActiveRecord::Base
set_table_name “hey”
end
=> nil
A.table_name
=> “hey”
class B < ActiveRecord::Base
ActiveRecord::Base.set_table_name “bumble”
end
=> nil
B.table_name
=> “bumble”
ActiveRecord::Base.table_name
=> “bumble”
A.table_name
=> “hey”
class C < ActiveRecord::Base
ActiveRecord::Base.set_table_name “clamp”
end
=> nil
C.table_name
=> “clamp”
class D < ActiveRecord::Base
end
=> nil
D.table_name
=> “clamp”
So:
I don’t think that calling ActiveRecord::Base is a good idea, and
You need further investigation of why
class Regionalindex < ActiveRecord::Base
set_table_name “RegionalIndex”
set_primary_key “IndexID”
end