edub4rt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Apr-15 22:12 UTC
Same model over multiple databases problem
Hello, I run many gameservers (about 10), each gameserver has a different database and all gameserver''s databases has the table "players" which is associated to the model Player. So every time I want to work with the Player model I need connect to a different database depending on which gameserver I am working on. My problem is that I need to make rails choose which database to use before creating/loading the model Player. I know which database to use because there is a central database with the table players_map that has the name of all players and tells me which gameserver database that player is. So in resume, any ideas how can I make rails to select the database connection before working with a model? Thanks, Eduardo Bart -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
database yml: external_db: adapter: oracle database: ext_db username: ext_user password: ext_password host: ext_host model: establish_connection :external_db On Apr 15, 5:12 pm, "edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I run many gameservers (about 10), each gameserver has a different > database and all gameserver''s databases has the table "players" which > is associated to the model Player. So every time I want to work with > the Player model I need connect to a different database depending on > which gameserver I am working on. > > My problem is that I need to make rails choose which database to use > before creating/loading the model Player. I know which database to use > because there is a central database with the table players_map that > has the name of all players and tells me which gameserver database > that player is. > > So in resume, any ideas how can I make rails to select the database > connection before working with a model? > > Thanks, > Eduardo Bart-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
edub4rt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2010-Apr-16 01:28 UTC
Re: Same model over multiple databases problem
You didn''t get it. If a make a model like: class Player < ActiveRecord::Base establish_connection :gameserver1_database ... end Then every Player model will connect to gameserver1_database and retrieve only player from there: @player = Player.find(:first) What I want is something more flexible that allows me to select which database to use, like this fake code: @player = Player.find(:first, :database => :gameserver1_database) On Apr 15, 9:57 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> database yml: > > external_db: > adapter: oracle > database: ext_db > username: ext_user > password: ext_password > host: ext_host > > model: > > establish_connection :external_db > > On Apr 15, 5:12 pm, "edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hello, > > > I run many gameservers (about 10), each gameserver has a different > > database and all gameserver''s databases has the table "players" which > > is associated to the model Player. So every time I want to work with > > the Player model I need connect to a different database depending on > > which gameserver I am working on. > > > My problem is that I need to make rails choose which database to use > > before creating/loading the model Player. I know which database to use > > because there is a central database with the table players_map that > > has the name of all players and tells me which gameserver database > > that player is. > > > So in resume, any ideas how can I make rails to select the database > > connection before working with a model? > > > Thanks, > > Eduardo Bart > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ya I thought about it after I sent it here you go: look at the bottom: http://railsforum.com/viewtopic.php?id=24338 On Apr 15, 8:28 pm, "edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You didn''t get it. > > If a make a model like: > > class Player < ActiveRecord::Base > establish_connection :gameserver1_database > ... > end > > Then every Player model will connect to gameserver1_database and > retrieve only player from there: > @player = Player.find(:first) > > What I want is something more flexible that allows me to select which > database to use, like this fake code: > @player = Player.find(:first, :database => :gameserver1_database) > > On Apr 15, 9:57 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > database yml: > > > external_db: > > adapter: oracle > > database: ext_db > > username: ext_user > > password: ext_password > > host: ext_host > > > model: > > > establish_connection :external_db > > > On Apr 15, 5:12 pm, "edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <edub...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hello, > > > > I run many gameservers (about 10), each gameserver has a different > > > database and all gameserver''s databases has the table "players" which > > > is associated to the model Player. So every time I want to work with > > > the Player model I need connect to a different database depending on > > > which gameserver I am working on. > > > > My problem is that I need to make rails choose which database to use > > > before creating/loading the model Player. I know which database to use > > > because there is a central database with the table players_map that > > > has the name of all players and tells me which gameserver database > > > that player is. > > > > So in resume, any ideas how can I make rails to select the database > > > connection before working with a model? > > > > Thanks, > > > Eduardo Bart > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.