# Single Table Inheritance

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance/119517>\
**Category:** Rails\
**Created:** [November 7, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/single-table-inheritance/119517 "2007-11-07T17:44:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [November 7, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/single-table-inheritance/119517/1 "2007-11-07T17:44:05Z")

</div>

Hi, a (hopefully) quick STE question.

I am loading a bunch of surveys of various types from csv files. The  
two  
relevant classes for this question:

# A wrapper around the loaded surveys

class Load \< ActiveRecord::Base  
require “fastercsv”  
include FileLoader

# Base survey relationship

has\_many :surveys

# Child relationships

has\_one :head\_survey  
has\_one :president\_survey  
has\_many :faculty\_surveys

# etc etc

end

# Base survey class

class Survey \< ActiveRecord::Base  
has\_one :load  
has\_many :survey\_responses

#factory method to generate the type of survery  
def self.factory(type, params)  
case type  
when ‘pres’  
return Board\_President\_Survey.new(params)  
when ‘membr’  
return Board\_Member\_Survey.new(params)  
when ‘busnss’  
return Business\_Survey.new(params)  
when ‘faclty’  
return Faculty\_Survey.new(params)  
when ‘dev’  
return Development\_Survey.new(params)  
when ‘head’  
return Head\_Survey.new(params)  
else  
return nil  
end  
end  
end

So a Load has many Surveys, but there are several survey types. Three  
of  
the Survey types are singletons (only one survey per Load) and the other  
types are has\_many’s.

I have a collection of surveys already instantiated:  
load.surveys

If I call:  
load.head\_survey

Will this reference the head\_survey from the existing collection, or  
will it  
perform another find?
