[bug?]default connection is to be used at the first connection

4 views
Skip to first unread message

Takayuki Kyowa

unread,
May 30, 2007, 10:15:59 AM5/30/07
to Dr Nic's Magic Models
[Facts]
When using MMC on Rails, the default connection is to be used at the
first connection.
Is this a MMC's bug?

[Confirmation]
It was confirmed by script/console command that ActiveRecord::Base
connection is used.
The log was shown in the following:

$ ruby script/console
>> ActiveRecord::Base.active_connections.keys
=> []
>> Slave::User.find :first
=> (snip)
>> ActiveRecord::Base.active_connections.keys
=> ["ActiveRecord::Base"]
>> Slave::User.find :first
=> (snip)
>> ActiveRecord::Base.active_connections.keys
=> ["ActiveRecord::Base",Slave]


The MMC module is just defined in the tail of enviroment.rb

require "magic_multi_connections"
module Slave
establish_connection :slave1
end

[Suggestion]
To comment out Line 7 in magic_multi_connections-1.0.0/lib/
magic_multi_connections/connected.rb

#return pre_connected_const_missing(const_id) rescue nil

After the fix was applyed, even at the first time the connection
specificated in the module. By now we have no trouble due to this fix,
the fix might occur some troubles...
Please give us some advices if you have better ideas.

[Environment]
ruby : ruby 1.8.5 (2006-08-25) [i686-linux]
mysql: 5.0.27-standard
rails: 1.2.3
mmc: 1.0.0

Nic Williams

unread,
May 30, 2007, 10:31:49 AM5/30/07
to magic...@googlegroups.com
Interesting idea - I'll check it out.

Thanks
Nic

#return pre_connected_const_missing (const_id) rescue nil


After the fix was applyed, even at the first time the connection
specificated in the module. By now we have no trouble due to this fix,
the fix might occur some troubles...
Please give us some advices if you have better ideas.

[Environment]
ruby : ruby 1.8.5 (2006-08-25) [i686-linux]
mysql: 5.0.27-standard
rails: 1.2.3
mmc: 1.0.0





--
Dr Nic Williams
http://myconfplan.com - plan the next conference you go to
http://www.drnicwilliams.com - Ruby/Rails/Javascript/Web2.0
skype: nicwilliams
(p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype)
(m) +4673 681 5093 (Swedish mobile)
(f) +61 7 3305 7572 (sends fax to my email)
Björnsonsgatan 153, 16 844 Bromma, Sweden

blakeage

unread,
Jun 21, 2007, 1:14:45 PM6/21/07
to Dr Nic's Magic Models
What is the purpose of this line of code? Seems like it's just
recursively calling the function again? Also, I assume that the
intent of this function (const_missing) is to create the active record
model within the "slave" module's namespace, am I correct?

Thanks
Blake

> > #return pre_connected_const_missing(const_id) rescue nil


>
> > After the fix was applyed, even at the first time the connection
> > specificated in the module. By now we have no trouble due to this fix,
> > the fix might occur some troubles...
> > Please give us some advices if you have better ideas.
>
> > [Environment]
> > ruby : ruby 1.8.5 (2006-08-25) [i686-linux]
> > mysql: 5.0.27-standard
> > rails: 1.2.3
> > mmc: 1.0.0
>
> --

> Dr Nic Williamshttp://myconfplan.com- plan the next conference you go tohttp://www.drnicwilliams.com- Ruby/Rails/Javascript/Web2.0


> skype: nicwilliams
> (p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype)
> (m) +4673 681 5093 (Swedish mobile)
> (f) +61 7 3305 7572 (sends fax to my email)

> Bj rnsonsgatan 153, 16 844 Bromma, Sweden

Nic Williams

unread,
Jun 21, 2007, 1:47:31 PM6/21/07
to magic...@googlegroups.com
That's right, it creates a new class within the model's namespace, that is a subclass of the actual class you want. It then calls #establish_connection on the new class.

http://drnicacademy.com - Ruby/Rails training around the world
http://drnicwilliams.com - Ruby/Rails/Javascript/Web2.0

skype: nicwilliams
(p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype)
(m) +4673 681 5093 (Swedish mobile)
(f) +61 7 3305 7572 (sends fax to my email)
Fleminggatan 25, 112 26 Stockholm, Sweden

in...@initiatecommerce.com

unread,
Jul 16, 2007, 3:52:22 PM7/16/07
to Dr Nic's Magic Models
I've noticed that I need to, occasionally, reference Module::MyClass
first, before I use the Module -- but not always. I can't figure out
why. For example, if Module is a namespace for a secondary connection,
I may do the following:

Module::MyClass1.find(:all) #=> works as expected
Module::MyClass2.find(:all) #=> works as expected
Module::MyClass3.find(:all) #=> does not work -- uses the production
connection

However, the following does work:
Module::MyClass1.find(:all) #=> works as expected
Module::MyClass2.find(:all) #=> works as expected
Module::MyClass3
Module::MyClass3.find(:all) #=> works as expected

MyClass1, 2, and 3 are all direct descendants of ActiveRecord::Base.

Am I doing something terribly wrong? Does the above make sense? Thanks
in advance and sorry for the three posts in one day.

Erik


On Jun 21, 1:47 pm, "Nic Williams" <drnicwilli...@gmail.com> wrote:
> That's right, it creates a new class within the model's namespace, that is a
> subclass of the actual class you want. It then calls #establish_connection
> on the new class.
>

> > > Dr Nic Williamshttp://myconfplan.com-plan the next conference you go


> > tohttp://www.drnicwilliams.com-Ruby/Rails/Javascript/Web2.0
> > > skype: nicwilliams
> > > (p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype)
> > > (m) +4673 681 5093 (Swedish mobile)
> > > (f) +61 7 3305 7572 (sends fax to my email)
> > > Bj rnsonsgatan 153, 16 844 Bromma, Sweden
>

> --
> Dr Nic Williamshttp://drnicacademy.com- Ruby/Rails training around the worldhttp://drnicwilliams.com- Ruby/Rails/Javascript/Web2.0

Nic Williams

unread,
Jul 16, 2007, 4:39:51 PM7/16/07
to magic...@googlegroups.com
First person to figure this mystery out is a hero.

Nic

http://drnicacademy.com - Ruby/Rails training around the world
http://drnicwilliams.com - Ruby/Rails/Javascript/Web2.0

skype: nicwilliams
(p) +61 7 3102 3237 (Finds me anywhere in the world, via Skype)
(m) +4673 681 5093 (Swedish mobile)
(f) +61 7 3305 7572 (sends fax to my email)
mail) Tele2 AB, c/o Berit Bergstrom
Archimedesvagen 4, Bromma, 16866, Sweden
Reply all
Reply to author
Forward
0 new messages