# ActiveRecord model with multiple table?

**URL:** <https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903>\
**Category:** Rails\
**Created:** [May 18, 2008, 1:06am UTC](https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903 "2008-05-18T01:06:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xxdd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@xxdd](https://www.ruby-forum.com/u/xxdd)\
**Post date:** [May 18, 2008, 1:06am UTC](https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903/1 "2008-05-18T01:06:59Z")

</div>

Hello. I have large database of old web application (written in php).  
Want to rewrite in Rails.

But here is a problem.

My User data is split to 10 Table. named user\_0, user\_1,user\_2  
if user.id % 10 = 1 will store to user\_1 for (database scable reason)

But most people use rails is using 1 model =\> 1 table.

Is anyone here know about how to implement or any plugin to do 1 model  
=\> multiple table or have similar experience ?

---

<div class="post-metadata">

**Author:** ![xxdd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@xxdd](https://www.ruby-forum.com/u/xxdd)\
**Post date:** [May 18, 2008, 2:19am UTC](https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903/2 "2008-05-18T02:19:14Z")

</div>

xxdd wrote:

> Hello. I have large database of old web application (written in php).  
> Want to rewrite in Rails.
> 
> But here is a problem.
> 
> My User data is split to 10 Table. named user\_0, user\_1,user\_2  
> if user.id % 10 = 1 will store to user\_1 for (database scable reason)

What scaling issue is addressed by this remarkable approach?

---

<div class="post-metadata">

**Author:** ![xxdd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@xxdd](https://www.ruby-forum.com/u/xxdd)\
**Post date:** [May 18, 2008, 4:24am UTC](https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903/3 "2008-05-18T04:24:17Z")

</div>

That certainly is unusual. If you don’t want to (or cannot) convert  
the ten user tables into a single users table, I would consider  
creating a pure ruby class that was composed with a user model. The  
pure ruby class would be a proxy and you’d delegate most of the method  
calls to the instance that you find by querying the ten ‘sub-user’  
tables.

It’s possible that you could use this as a plan for migrating the data  
into one table, too. You could query from any table, but always save  
the data back to one. Eventually you’ll get all the active users over  
to one table. That’s probably more work than it’s worth but it’s an  
option.

On May 17, 8:19 pm, James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![xxdd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f9ae1b/32.png) [@xxdd](https://www.ruby-forum.com/u/xxdd)\
**Post date:** [May 18, 2008, 6:55am UTC](https://www.ruby-forum.com/t/activerecord-model-with-multiple-table/137903/4 "2008-05-18T06:55:09Z")

</div>

James B. wrote:

> xxdd wrote:

> > My User data is split to 10 Table. named user\_0, user\_1,user\_2  
> > if user.id % 10 = 1 will store to user\_1 for (database scable reason)
> 
> What scaling issue is addressed by this remarkable approach?

Allowing the database to ignore its own built-in block paging  
algorithms?

I suspect the original coder invented that beauty. In PhP, natch…

xxdd should read the /Rails Recipes/ chapter on legacy databases, then  
connect directly to that database. And she or he should then write and  
deploy new features in Rails while leaving the old system online. Don’t  
write Rails (or any app) for a long time without delivering anything.  
The  
best way to get your foot in the door is add one new feature with Rails,  
then give it to customers who can leave the old system online with the  
new  
one.

–  
Phlip
