# 4 Rails apps using the same table. How to streamline?

**URL:** <https://www.ruby-forum.com/t/4-rails-apps-using-the-same-table-how-to-streamline/197089>\
**Category:** Rails\
**Created:** [March 24, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/4-rails-apps-using-the-same-table-how-to-streamline/197089 "2009-03-24T17:51:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [March 24, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/4-rails-apps-using-the-same-table-how-to-streamline/197089/1 "2009-03-24T17:51:28Z")

</div>

Hi,

I have 4 apps using similar User tables(3 open source projects and one  
in-house app). I’m trying to merge into one shared database User table  
(external to all 4 apps).

* * *

I’m using the following code in the User model to switch to the shared  
database:

class User \< ActiveRecord::Base

# GSL, 03/18/09 - Add reference to external ua database.

## User.establish\_connection ( :adapter =\> “mysql”, :host =\> “[example.corp.example.com](http://example.corp.example.com)”, :username =\> “root”, :password =\> “?”, :database =\> “ua\_production” )

Then, I have to switch the other models back:  
class Attachment \< ActiveRecord::Base

# GSL, 03/18/09 - Add reference to external ua database.

Attachment.establish\_connection (  
:adapter =\> “mysql”,  
:host =\> “[example.corp.example.com](http://example.corp.example.com)”,  
:username =\> “root”,  
:password =\> “?”,  
:database =\> “redmine”  
)

* * *

I added the above to all the other models in my Redmine app.

So, now the views that are trying to do a SQL JOIN are bombing.

Is there an easier way?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [March 24, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/4-rails-apps-using-the-same-table-how-to-streamline/197089/2 "2009-03-24T18:53:02Z")

</div>

On Tue, Mar 24, 2009 at 11:50 AM, LaughingNinja  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So, now the views that are trying to do a SQL JOIN are bombing.
> 
> Is there an easier way?

Are you sure something’s not correct with your model relationships?  
What do they look like exactly? What do the errors from the bombing  
look like?

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![LaughingNinja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e9bcb4/32.png) [@LaughingNinja](https://www.ruby-forum.com/u/LaughingNinja)\
**Post date:** [March 24, 2009, 7:06pm UTC](https://www.ruby-forum.com/t/4-rails-apps-using-the-same-table-how-to-streamline/197089/3 "2009-03-24T19:06:37Z")

</div>

## LaughingNinja wrote:

> I added the above to all the other models in my Redmine app.
> 
> So, now the views that are trying to do a SQL JOIN are bombing.

Are you trying to join tables from different connections/database  
instances?
