# Rails: has\_many issue

**URL:** <https://www.ruby-forum.com/t/rails-has-many-issue/53455>\
**Category:** Ruby\
**Created:** [February 6, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/rails-has-many-issue/53455 "2006-02-06T13:46:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [February 6, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/rails-has-many-issue/53455/1 "2006-02-06T13:46:05Z")

</div>

Hi,  
I’m trying to work out how to tackle a particular problem in rails.

I have some data. A lot of data (well not NSA style a lot of data, but  
a lot for me: 1Gb at the moment, more to come).

I’m building a ruby application to process and view this data, and have  
been working round using rails as a front end - do the heavy lifting  
using some maths libraries, then use rails to display results, etc.

The problem that I have is as follows: The natural organisation is that  
the data consists of DataSets, each DataSet is a group of related time  
series (Series), and each series consists fo a set of observations,  
each Observation having a set of parameters.

So far, so good. The logical layout of the data is something like

DataSet has\_many Series  
Series has\_many Observation

The problem is that I need to be able to do processing of the data  
offline at a later point, and one of the thngs I am doing is developing  
new ways of dealing with the data. So I need to apply a transformation  
to each Observation. The transformed data hasn’t lost anything, and it  
still comes in Series which belong to a dataset.

One option would be

DataSet has\_many Series  
DataSet has many TransformedSeries  
Series has\_many Observation  
TransformedSeries has many TransformedObservation

but the problem is that every time I add a new transformation, I need  
to change my DB schema, etc, and add new code in to DataSet - which I  
personally believe is quite ugly!

What I would really like is for the Series to have a field  
(series\_type) which contains the name of the table to look up the  
Observation in. So, depending on the value in the series\_type field,  
Series would perform has\_many operations using the Observation table or  
the TransformedObservation table (or whatever other table).

Is there any easy way to achieve this without directly hacking  
has\_many?

Best regards,

Treefrog

---

<div class="post-metadata">

**Author:** ![treefrog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c68b51/32.png) [@treefrog](https://www.ruby-forum.com/u/treefrog)\
**Post date:** [February 6, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/rails-has-many-issue/53455/2 "2006-02-06T20:43:38Z")

</div>

On Feb 6, 2006, at 4:43 AM, treefrog wrote:

> Hi,  
> I’m trying to work out how to tackle a particular problem in rails.

You should use the Rails mailing list then.

[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Eric H. - removed\_email\_address@domain.invalid - [http://segment7.net](http://segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
