Forum: Ruby on Rails Magic multi connections with association problem

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.
Af3cecc8af253b5acd3c09c5b67c0074?d=identicon&s=25 Valentino Lun (on9west)
on 2009-04-16 14:24
Dear all

I am using magic multi connections, there is some problem when using
association. How can I dynamic determine the module name (i.e.
A::Request, B::Request) in activerecord association.

Below is my code:

module A
    establish_connection :A
end

module B
    establish_connection :B
end

# and many module....

class Request < ActiveRecord::Base
    set_table_name "request"
    set_primary_key "req_reqno"
    has_many :testrslt, :class_name => "Testrslt", :foreign_key =>
"testrslt_reqno"
end

class Testrslt < ActiveRecord::Base
    set_table_name "testrslt"
    belongs_to :request, :class_name => "Request", :foreign_key =>
"testrslt_reqno"
end

>> a = DBA::Request.last
=> It is ok
>> a.testrslt
=> # The association is not referring to A connection....

I want the :class_name as below if A connection is used....

class Request < ActiveRecord::Base
    set_table_name "request"
    set_primary_key "req_reqno"
    has_many :testrslt, :class_name => "A::Testrslt", :foreign_key =>
"testrslt_reqno"
end

class Testrslt < ActiveRecord::Base
    set_table_name "testrslt"
    belongs_to :request, :class_name => "A::Request", :foreign_key =>
"testrslt_reqno"
end

Part of my gem list
magic_multi_connections (1.2.1)
rails (2.2.2)

Please advise.

Many thanks
Valentino
This topic is locked and can not be replied to.