# AR model using a table form another database

**URL:** <https://www.ruby-forum.com/t/ar-model-using-a-table-form-another-database/144215>\
**Category:** Rails\
**Created:** [July 26, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/ar-model-using-a-table-form-another-database/144215 "2008-07-26T21:16:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [July 26, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/ar-model-using-a-table-form-another-database/144215/1 "2008-07-26T21:16:22Z")

</div>

Is there a way to configure an ActiveRecord model to use table in  
another  
database?

I ask this becouse our user table is a centralized one, used by many  
other  
applications. These applications use various ways/abstratctions to  
authenticate against this authentication data-source. The simples way I  
can  
think to do this with this Rails app would be to set the User model to  
use  
this table.

Any way to do this? Maybe a little hack in AR through a plugin?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mhfs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@mhfs](https://www.ruby-forum.com/u/mhfs)\
**Post date:** [July 27, 2008, 6:57pm UTC](https://www.ruby-forum.com/t/ar-model-using-a-table-form-another-database/144215/2 "2008-07-27T18:57:33Z")

</div>

In database.yml file. just like development, production and test  
database info add another one called user\_db and add information for  
that.  
Then in your user model do something like:  
class User \< ActiveRecord::Base  
establish\_connection :user\_db  
…  
end

Hope this should work fine.

[http://www.sphred.com](http://www.sphred.com)

> **[Nasir Jamal](https://nasir.wordpress.com)**
>
> on ruby, rails and other stuff

On Jul 26, 8:15 pm, “Marcelo de Moraes S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
