# Suggestions for a complex model appreciated

**URL:** <https://www.ruby-forum.com/t/suggestions-for-a-complex-model-appreciated/92724>\
**Category:** Rails\
**Created:** [April 23, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/suggestions-for-a-complex-model-appreciated/92724 "2007-04-23T14:44:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimmoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e19adc/32.png) [@kimmoke](https://www.ruby-forum.com/u/kimmoke)\
**Post date:** [April 23, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/suggestions-for-a-complex-model-appreciated/92724/1 "2007-04-23T14:44:39Z")

</div>

I have a rather complex legacy db I’d like to access via ActiveRecord  
and I’m not sure how to model it wisely.

I have a lot of tables that follow the following format:

Table name: CDM\_CONFIGURATION\_ITEMS  
Primary key: CIT\_OID

Then extra columns for CI’s in another table:

Table name: CDM\_CONFIGURATION\_ITEMS\_X  
Primary key: XCIT\_CIT\_OID \<-- links to the CIT\_OID above

And not to be to simple, a bunch of more extra columns in tables such  
as:

Table name: CDM\_CONFIGURATION\_ITEMS\_X\_SD\_1  
Primary key: XCIT1\_CIT\_OID \<-- links to the CIT\_OID in the top level  
…  
Table name: CDM\_CONFIGURATIO\_ITEMS\_X\_SD\_10  
Primary key: XCIT10\_CIT\_OID

Now if I make a normal model I’d access the extra columns like:  
ci.ci\_x\_1.xcit1\_maximum\_installations  
which doesn’t seem like fun at all, since I’d always have to look up  
which table each column is in from a list. There are a lot of columns  
per table and listing them all for send() in the main model doesn’t look  
like an elegant solution either and would require a lot of handiwork to  
collect all the column names. I guess iterating through all the extra  
models and asking if they have the method requested via method\_missing  
would cause AR to fetch the row in question from every table? Of course  
the column names could be cached… Getting complicated. Ideas?
