Associations over 37 different tables with has_one

Hi all,

I have 37 different tables with each having its own sort column (sort implying that the main data of that table is sorted on that particular column). Each of these sort columns is different and unique.

To make things easier for myself I created an inheritance template where each of the 37 tables inherits from one templated controller and one templated model. They all use the same methods. So all 37 controllers/models are basically empty and the inherited/templated controller and model contain the objects/methods.

I'm now creating a master table that needs to pull the data from each of those 37 tables and the sort columns, perform calculations, and then save the refined calculations back to itself (the master table).

I'm trying to figure out a proper way to setup the associations. All I'm doing is gathering data from those tables to calculate further values. My master data table belongs to my team model and the rest of the data tables belong to my team model. The current associations are:

class Team < ActiveRecord::Base   has_many :master_tables   has_many :inheritance_templates end

class MasterTable < ActiveRecord::Base   belongs_to :team end

class InheritanceTemplate < ActiveRecord::Base   self.abstract_class = true   belongs_to :team end

class DataOne < InheritanceTemplate end class DataTwo < InheritanceTemplate end class DataThree < InheritanceTemplate end

I'm not sure how the association should be setup between the Master Table model and the Inheritance Template model. They both belong to team.

Assume that I want to retrieve the following:

DataOne.colomnonedata DataTwo.columntwodata DataThree.columnthreedata

I could do:

@one = DataOne.find(:all) @two = DataTwo.find(:all) @three = DataThree.find(:all)

and point to a custom method that searches for the specific column and only returns results for that column but I figured there might be a better approach to all of this.

Any help would be appreciative..

The reason why I'm asking this is I'm thinking that perhaps there's "no association" at all between the master table and the other tables. The reason why I believe this is due to the fact that I'm pulling data from those tables, changing them, and saving refined data to the master table. Therefore, no columns from the tables I'm gathering data for belong to the master table.

However, the master table depends on the data from those tables in order to get its own numbers...

Älphä Blüë wrote:

Hi all,

I have 37 different tables with each having its own sort column

[...]

I'm now creating a master table that needs to pull the data from each of those 37 tables and the sort columns, perform calculations, and then save the refined calculations back to itself (the master table).

I'm trying to figure out a proper way to setup the associations. All I'm doing is gathering data from those tables to calculate further values. My master data table belongs to my team model and the rest of the data tables belong to my team model.

[...]

I'm not sure how the association should be setup between the Master Table model and the Inheritance Template model. They both belong to team.

It sounds like that's all you need. I don't see why InheritanceTemplate would come into the associations

[...]

Any help would be appreciative..

No, help would be appreciated. You'd be appreciative of any help. :smiley:

No, help would be appreciated. You'd be appreciative of any help. :smiley:

LOL - thanks Marnen. You would not believe how often my fiance corrects me on my improper use of words.. :slight_smile:

I "appreciate" the help mate.