-
Notifications
You must be signed in to change notification settings - Fork 11
Embeddables
pjmorse edited this page Oct 18, 2012
·
2 revisions
These classes all define lists of Embeddable classes in order to define has_many associations, e.g. (from app/models/investigation.rb
):
@@embeddable_klasses.each do |klass|
eval %!has_many :#{klass.name[/::(\w+)$/, 1].underscore.pluralize}, :class_name => '#{klass.name}',
:finder_sql => proc { "SELECT #{klass.table_name}.* FROM #{klass.table_name}
INNER JOIN page_elements ON #{klass.table_name}.id = page_elements.embeddable_id AND page_elements.embeddable_type = '#{klass.to_s}'
INNER JOIN pages ON page_elements.page_id = pages.id
INNER JOIN sections ON pages.section_id = sections.id
INNER JOIN activities ON sections.activity_id = activities.id
WHERE activities.investigation_id = \#\{id\}" }!
end
app/models/activity.rb
app/models/investigation.rb
app/models/page.rb
app/models/section.rb
app/models/user.rb
N.B. the User model does this differently, and with a slightly different list, but the other four all do pretty much the same thing.
Activity, Investigation and Section all use the same list of Embeddables:
[ Embeddable::Xhtml,
Embeddable::OpenResponse,
Embeddable::MultipleChoice,
Embeddable::DataTable,
Embeddable::DrawingTool,
Embeddable::DataCollector,
Embeddable::LabBookSnapshot,
Embeddable::InnerPage,
Embeddable::MwModelerPage,
Embeddable::NLogoModel,
Embeddable::RawOtml,
Embeddable::Biologica::World,
Embeddable::Biologica::Organism,
Embeddable::Biologica::StaticOrganism,
Embeddable::Biologica::Chromosome,
Embeddable::Biologica::ChromosomeZoom,
Embeddable::Biologica::BreedOffspring,
Embeddable::Biologica::Pedigree,
Embeddable::Biologica::MultipleOrganism,
Embeddable::Biologica::MeiosisView,
Embeddable::Smartgraph::RangeQuestion]
Page adds three extras:
Embeddable::ImageQuestion
Embeddable::SoundGrapher
Embeddable::VideoPlayer
Page also wraps support of Embeddable::RawOtml
in a conditional.
User only supports eight:
has_many :data_collectors, :class_name => 'Embeddable::DataCollector'
has_many :xhtmls, :class_name => 'Embeddable::Xhtml'
has_many :open_responses, :class_name => 'Embeddable::OpenResponse'
has_many :multiple_choices, :class_name => 'Embeddable::MultipleChoice'
has_many :data_tables, :class_name => 'Embeddable::DataTable'
has_many :drawing_tools, :class_name => 'Embeddable::DrawingTool'
has_many :mw_modeler_pages, :class_name => 'Embeddable::MwModelerPage'
has_many :n_logo_models, :class_name => 'Embeddable::NLogoModel'