# Multiple databases and fixtures problems

**URL:** <https://www.ruby-forum.com/t/multiple-databases-and-fixtures-problems/92914>\
**Category:** Rails\
**Created:** [April 25, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/multiple-databases-and-fixtures-problems/92914 "2007-04-25T17:33:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lodestone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e495f1/32.png) [@lodestone](https://www.ruby-forum.com/u/lodestone)\
**Post date:** [April 25, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/multiple-databases-and-fixtures-problems/92914/1 "2007-04-25T17:33:30Z")

</div>

I’m working on a Rails app which makes use of two distinct (i.e. not  
master-slave) databases, one ours and the other a central data store  
which holds the core data we’re using.

We have two sets of model classes, and the central store’s models are  
in a plugin and are namespaced (more than one project use them). So,  
we have classes like:

CentralStore::ModelName \< ActiveRecord::Base

for the central store, and

ModelName \< ActiveRecord::Base

for ours. Our first big problem was with fixtures for the namespaced  
models. I shimmed the ActiveRecord fixtures mechanism so you could  
pass a block with the connection to the db you wanted the fixtures  
created in and the right thing would be done:

class TestClass \< Test::Unit::TestCase  
fixtures(:model\_one, :model\_two) {CentralStore::Base.connection}

That’s only mapping .yml files to DB table names though: The big  
problem is that ActiveRecord’s fixture helper methods look for class  
names corresponding to table names (derived from the .yml files),  
which means that no namespaced models will be found (table name ==  
‘model\_name’, class == ‘CentralStore::ModelName’).

The easy solution is to simply include the module in your  
test\_helper.rb. However, that leaves you open to the thing that bit me  
today: if your central store’s models gain a class with the same name  
as one of yours (or vice versa).

Of course, the models are namespaced, so in application code there  
isn’t a problem. However, in tests, the models clash (you get a  
superclass mismatch error and your tests just don’t run…) and you  
can’t have fixtures for both tables.

My short term solution is to rename the local model, but has anyone  
run into the same issue and done something elegant about it? I don’t  
want to rewrite the fixtures stack only to discover that someone else  
has a less intrusive solution…

Thanks,

Matt
