<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Lost in multiple rails?</title>
	<atom:link href="http://blog.amber.org/2005/06/30/lost-in-multiple-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/</link>
	<description>Thoughts of a minor lunatic</description>
	<pubDate>Fri, 29 Aug 2008 23:01:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Dorival Pedroso</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-39848</link>
		<dc:creator>Dorival Pedroso</dc:creator>
		<pubDate>Mon, 06 Nov 2006 20:22:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-39848</guid>
		<description>I have the same situation as *Chris*. It would be nice to have a clean way to to that. Thanks.</description>
		<content:encoded><![CDATA[<p>I have the same situation as <strong>Chris</strong>. It would be nice to have a clean way to to that. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MikeW</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-38373</link>
		<dc:creator>MikeW</dc:creator>
		<pubDate>Wed, 01 Nov 2006 04:31:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-38373</guid>
		<description>I'm running into an issue with relationships across multiple databases.  I have 2 different applications in place running on 2 different databases.  Everything is working just fine, though I had to fix an issue with it.  The same issue I'm about to get to.  I now want to add a third application that interacts with both applications.  The first app is an inventory control program that runs locally at the company.  This is in case the internet ever goes down, which unfortunately happens on occasion, they can still operate.  Next is a site served elsewhere for their sales reps to use.  Everything in that database is stored on the web server, except for the user table which already exists on the company database.  A problem occured when using code like this:

@customer.users

where a User habtm Customers.  The error that I got indicated that the linker table didn't exist in the database that the users were stored in.  But when I switched the order of the code:

@user.customers

it worked.  So this must mean that I can never call a method on a model that is stored in one database and include a model from another database, which will essentially kill any possibilities of eager loading information.  

I was able to bypass the issue in the first scenario, but now with my third application, it will be interacting a lot between the two databases.  About half will be in one database, half in another.  Is there a better way of approaching this problem, or a way to get around this issue?  Or am I just doomed to having to pulling in tons of information and having to work with is server side?</description>
		<content:encoded><![CDATA[<p>I&#8217;m running into an issue with relationships across multiple databases.  I have 2 different applications in place running on 2 different databases.  Everything is working just fine, though I had to fix an issue with it.  The same issue I&#8217;m about to get to.  I now want to add a third application that interacts with both applications.  The first app is an inventory control program that runs locally at the company.  This is in case the internet ever goes down, which unfortunately happens on occasion, they can still operate.  Next is a site served elsewhere for their sales reps to use.  Everything in that database is stored on the web server, except for the user table which already exists on the company database.  A problem occured when using code like this:</p>
<p>@customer.users</p>
<p>where a User habtm Customers.  The error that I got indicated that the linker table didn&#8217;t exist in the database that the users were stored in.  But when I switched the order of the code:</p>
<p>@user.customers</p>
<p>it worked.  So this must mean that I can never call a method on a model that is stored in one database and include a model from another database, which will essentially kill any possibilities of eager loading information.  </p>
<p>I was able to bypass the issue in the first scenario, but now with my third application, it will be interacting a lot between the two databases.  About half will be in one database, half in another.  Is there a better way of approaching this problem, or a way to get around this issue?  Or am I just doomed to having to pulling in tons of information and having to work with is server side?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: petrilli</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-35960</link>
		<dc:creator>petrilli</dc:creator>
		<pubDate>Sat, 21 Oct 2006 02:11:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-35960</guid>
		<description>Actually, Erwan, what you do is attach your classes to the database directly. So if you had a class "Foo" that needed to be retrieved from the non-default database, you would use:

Foo.establish_connection ...

Like that.</description>
		<content:encoded><![CDATA[<p>Actually, Erwan, what you do is attach your classes to the database directly. So if you had a class &#8220;Foo&#8221; that needed to be retrieved from the non-default database, you would use:</p>
<p>Foo.establish_connection &#8230;</p>
<p>Like that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erwan</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-35145</link>
		<dc:creator>Erwan</dc:creator>
		<pubDate>Thu, 19 Oct 2006 03:01:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-35145</guid>
		<description>there is no ActiveRecord::Base.establish_connection line in my environment.rb file... where could I find it ?</description>
		<content:encoded><![CDATA[<p>there is no ActiveRecord::Base.establish_connection line in my environment.rb file&#8230; where could I find it ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-28542</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 12 Sep 2006 21:02:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-28542</guid>
		<description>I'm trying out rails on a new app for multiple customers where each customer will have a seperate database of 38 tables.  I need a clean method of selecting a database based on user input on the login form.  For example if the user is not logged in already they will be presented with a form containing fields for username, password, and account.  The account name will corrispond to the database that they should be accessing and their username and password will then be validated in a user table in that same database.  Is there a clean way to do this where I don't have to add each database to the database.yml?  We hoping for around 100 customers for this app.</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying out rails on a new app for multiple customers where each customer will have a seperate database of 38 tables.  I need a clean method of selecting a database based on user input on the login form.  For example if the user is not logged in already they will be presented with a form containing fields for username, password, and account.  The account name will corrispond to the database that they should be accessing and their username and password will then be validated in a user table in that same database.  Is there a clean way to do this where I don&#8217;t have to add each database to the database.yml?  We hoping for around 100 customers for this app.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lightsedge</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-23034</link>
		<dc:creator>lightsedge</dc:creator>
		<pubDate>Tue, 15 Aug 2006 02:26:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-23034</guid>
		<description>See p65 of Rails Recipes by Chad Fowler</description>
		<content:encoded><![CDATA[<p>See p65 of Rails Recipes by Chad Fowler</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-7411</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Thu, 18 May 2006 21:37:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-7411</guid>
		<description>I just came across an interesting problem while trying this out. I have five tables I need to access in my rails app. Three are in Oracle and two are in PostgreSQL.

I first had the Oracle tables extend an ActiveRecord::Base subclass named Auth so that in environment.rb I could just write:

Auth.establish_connection "auth_#{ENV["RAILS_ENV"]}"

This worked well, and only one connection to Oracle was created.

However, I then tried to do the same with my PostgreSQL models, creating an ActiveRecord::Base subclass named Dns, and the following line in environment.rb:

Dns.establish_connection "dns_#{ENV["RAILS_ENV"]}"

This didn't work so well, and I'm not sure if the problem is in the Oracle adapter or the PostgreSQL adapter.

The issue is that the PostgreSQL adapter complains that it can't find a table named "dns". The only reason I'm using subclassing is as a hack to not have to specify the database connection used by every model class, which causes a different connection to be used for each one, which prevents any sort of transactional behavior between those models and wastes database resources.

In the end, what I'm doing is the following in environment.rb:

Record.establish_connection "dns_#{ENV["RAILS_ENV"]}"
Redirect.connection = Record.connection

This seems kind of nasty, but at least it gives me just one connection. I'd like to see a cleaner solution, but it's something you can use if you run into the same situation.</description>
		<content:encoded><![CDATA[<p>I just came across an interesting problem while trying this out. I have five tables I need to access in my rails app. Three are in Oracle and two are in PostgreSQL.</p>
<p>I first had the Oracle tables extend an ActiveRecord::Base subclass named Auth so that in environment.rb I could just write:</p>
<p>Auth.establish_connection &#8220;auth_#{ENV[&#8220;RAILS_ENV&#8221;]}&#8221;</p>
<p>This worked well, and only one connection to Oracle was created.</p>
<p>However, I then tried to do the same with my PostgreSQL models, creating an ActiveRecord::Base subclass named Dns, and the following line in environment.rb:</p>
<p>Dns.establish_connection &#8220;dns_#{ENV[&#8220;RAILS_ENV&#8221;]}&#8221;</p>
<p>This didn&#8217;t work so well, and I&#8217;m not sure if the problem is in the Oracle adapter or the PostgreSQL adapter.</p>
<p>The issue is that the PostgreSQL adapter complains that it can&#8217;t find a table named &#8220;dns&#8221;. The only reason I&#8217;m using subclassing is as a hack to not have to specify the database connection used by every model class, which causes a different connection to be used for each one, which prevents any sort of transactional behavior between those models and wastes database resources.</p>
<p>In the end, what I&#8217;m doing is the following in environment.rb:</p>
<p>Record.establish_connection &#8220;dns_#{ENV[&#8220;RAILS_ENV&#8221;]}&#8221;<br />
Redirect.connection = Record.connection</p>
<p>This seems kind of nasty, but at least it gives me just one connection. I&#8217;d like to see a cleaner solution, but it&#8217;s something you can use if you run into the same situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Workin&#8217; on it. &#187; Rubicizing</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-6318</link>
		<dc:creator>Workin&#8217; on it. &#187; Rubicizing</dc:creator>
		<pubDate>Wed, 19 Apr 2006 03:34:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-6318</guid>
		<description>[...] Now that this things working, it&#8217;s time to break it. In my very first iteration I created the app with a single db, but in reality - it&#8217;s going to span two. Today I needed to figure out exactly how this is done. From what I read, this is something that is quite possible&#8230; but just isn&#8217;t all that straight forward. [...]</description>
		<content:encoded><![CDATA[<p>[...] Now that this things working, it&#8217;s time to break it. In my very first iteration I created the app with a single db, but in reality &#8211; it&#8217;s going to span two. Today I needed to figure out exactly how this is done. From what I read, this is something that is quite possible&#8230; but just isn&#8217;t all that straight forward. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: petrilli</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-5329</link>
		<dc:creator>petrilli</dc:creator>
		<pubDate>Thu, 09 Feb 2006 21:06:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-5329</guid>
		<description>There is actually a "good introductory article":http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases in the Rails wiki on how to do this.  It worked fine for me, though it's perhaps not the way I would have approached the problem.</description>
		<content:encoded><![CDATA[<p>There is actually a <a href="http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases">good introductory article</a> in the Rails wiki on how to do this.  It worked fine for me, though it&#8217;s perhaps not the way I would have approached the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deniz</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-5327</link>
		<dc:creator>Deniz</dc:creator>
		<pubDate>Thu, 09 Feb 2006 18:23:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-5327</guid>
		<description>Hi,
Since I am very new to RoR, there are a lot of things I don't know. I am very confused about connecting multiple databases from one application. My application works great for single database and I came to a point that I am required to connect a second database and pull some information and return results.
I still have no idea how to do this yet, could you by chance explain this a little more on your blog..
Thank you
Deniz.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Since I am very new to RoR, there are a lot of things I don&#8217;t know. I am very confused about connecting multiple databases from one application. My application works great for single database and I came to a point that I am required to connect a second database and pull some information and return results.<br />
I still have no idea how to do this yet, could you by chance explain this a little more on your blog..<br />
Thank you<br />
Deniz.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louis</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-3459</link>
		<dc:creator>Louis</dc:creator>
		<pubDate>Sat, 01 Oct 2005 19:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-3459</guid>
		<description>Thanks so much for your comment, Michael. Step 2 was just what I needed to clarify the API docs on establish_connection. (Woot. The hardest part with Rails is trying to do things "right" :p Once you know how, it seems so obvious ... Sigh.)</description>
		<content:encoded><![CDATA[<p>Thanks so much for your comment, Michael. Step 2 was just what I needed to clarify the API docs on establish_connection. (Woot. The hardest part with Rails is trying to do things &#8220;right&#8221; :p Once you know how, it seems so obvious &#8230; Sigh.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: petrilli</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-2068</link>
		<dc:creator>petrilli</dc:creator>
		<pubDate>Fri, 01 Jul 2005 04:07:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-2068</guid>
		<description>Wow, I'm flattered.  Thanks for the pointer Michael.  I had gotten some leads from @tufty@ on @#rubyonrails@ and had started to go there, unfortunately I've run smack into some scaffold problems.  It is late, and I just got back, so I will post about them more tomorrow.

The solution you gave is a bit more elegant, and solves that problem.  Now I just have to figure out how to solve my scaffold problem.</description>
		<content:encoded><![CDATA[<p>Wow, I&#8217;m flattered.  Thanks for the pointer Michael.  I had gotten some leads from <code>tufty</code> on <code>#rubyonrails</code> and had started to go there, unfortunately I&#8217;ve run smack into some scaffold problems.  It is late, and I just got back, so I will post about them more tomorrow.</p>
<p>The solution you gave is a bit more elegant, and solves that problem.  Now I just have to figure out how to solve my scaffold problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Koziarski</title>
		<link>http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-2067</link>
		<dc:creator>Michael Koziarski</dc:creator>
		<pubDate>Thu, 30 Jun 2005 22:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.amber.org/2005/06/30/lost-in-multiple-rails/#comment-2067</guid>
		<description>Hey there,

You've actually got a few of the core rails team reading your blog.  Your 'the red herring of performance' piece led a lot of us to subscribe.

So, here's some help:

1) Edit database.yml and add the configuration for your second database.  Just like the others, but instead of using the environment as the key, use some other name

2) You want to make the Course.establish_connection call in your environment.rb file, just under the ActiveRecord::Base.establish_connection

Course.establish_connection "your_config_name"

And if you wanted per-environment options for the second database,   just call them something like "your_config_name_production" and call Course.establish_connection "your_connection_name#{RAILS_ENV}"

</description>
		<content:encoded><![CDATA[<p>Hey there,</p>
<p>You&#8217;ve actually got a few of the core rails team reading your blog.  Your &#8216;the red herring of performance&#8217; piece led a lot of us to subscribe.</p>
<p>So, here&#8217;s some help:</p>
<p>1) Edit database.yml and add the configuration for your second database.  Just like the others, but instead of using the environment as the key, use some other name</p>
<p>2) You want to make the Course.establish_connection call in your environment.rb file, just under the ActiveRecord::Base.establish_connection</p>
<p>Course.establish_connection &#8220;your_config_name&#8221;</p>
<p>And if you wanted per-environment options for the second database,   just call them something like &#8220;your_config_name_production&#8221; and call Course.establish_connection &#8220;your_connection_name#{RAILS_ENV}&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.303 seconds -->
