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?