Set_table_name on RoR 1.2.4

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

everything is performing OK.

Do you think it’s a little puzzling?

On 10/11/07, dima [email protected] wrote:

class Regionalindex < ActiveRecord::Base
End

everything is performing OK.

Do you think it’s a little puzzling?

Puzzling, and scary.

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:

  1. I don’t think that calling ActiveRecord::Base is a good idea, and

  2. You need further investigation of why
    class Regionalindex < ActiveRecord::Base
    set_table_name “RegionalIndex”
    set_primary_key “IndexID”
    end

Isn’t working.

Perhaps it’s an issue with the mssql adapter?

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/