# Magic multi connections with association problem

**URL:** <https://www.ruby-forum.com/t/magic-multi-connections-with-association-problem/165694>\
**Category:** Rails\
**Created:** [April 16, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/magic-multi-connections-with-association-problem/165694 "2009-04-16T14:24:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [April 16, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/magic-multi-connections-with-association-problem/165694/1 "2009-04-16T14:24:57Z")

</div>

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
