# Legacy database and set\_table\_name

**URL:** <https://www.ruby-forum.com/t/legacy-database-and-set-table-name/148245>\
**Category:** Rails\
**Created:** [September 10, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/legacy-database-and-set-table-name/148245 "2008-09-10T21:49:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [September 10, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/legacy-database-and-set-table-name/148245/1 "2008-09-10T21:49:48Z")

</div>

I’m trying like crazy to wrap a rails app around a legacy oracle  
database. This app will not be mutating any data in the database,  
only viewing it. Here’s a 30 second description of the “schema”.

There is a master table for a health care claim (I will call it  
claim\_master), and this table has a unique id for the claim, as well  
as a type and a status. Type can be 1 of about a dozen possible  
values. Status is either paid, suspended or denied. Then we have  
several other tables, split up by claim type and status, that hold  
extra claims data. So claims of type A with a paid status would be  
in, say, claims\_a\_paid and a claim with type B with a deny status  
would be in claim\_b\_deny.

I want to set up my models with associations, but the association must  
depend on values in the database. Take this:

class Claim \< ActiveRecord::Base  
has\_one :extra  
set\_table\_name “claim\_master”  
end

class ClaimExtra \< ActiveRecord::Base  
belongs\_to :claim  
set\_table\_name “???”  
end

The table name that belongs where the ??? is depends on data in the  
claim. Is there any rails magic I can use that can let this table  
name be dynamically constructed out of the results from the belongs\_to  
directive being executed?

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [September 10, 2008, 10:36pm UTC](https://www.ruby-forum.com/t/legacy-database-and-set-table-name/148245/2 "2008-09-10T22:36:43Z")

</div>

I’m probably out of my depth here, but since you’re not doing any  
writing, I wonder if you could get a view together on the oracle side  
that UNIONS the data from your various ClaimExtra tables, and then point  
rails at that as the source ‘table’ for ClaimExtra?

You could maybe even get fancy and pretend to be doing Single Table  
Inheritance on that view, if you wanted to e.g., have distinct  
DeniedTypeAClaim and SuspendedTypeBClaim classes…
