Revision 0bba6aae
Added by Ohad Levy almost 14 years ago
- ID 0bba6aae5598b368fd99a3c33f20d602e78261a5
app/models/operatingsystem.rb | ||
---|---|---|
|
||
# Emulate multiple inheritance from a virtual Family class
|
||
def after_initialize
|
||
extend eval("Family::#{Family::FAMILIES[family_id]}") if family_id
|
||
extend eval("Family::#{Family::FAMILIES[family_id]}") if defined? family_id and not family_id.nil?
|
||
end
|
||
|
||
def family
|
db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb | ||
---|---|---|
class CreateMediasOperatingsystemsAndMigrateData < ActiveRecord::Migration
|
||
def self.up
|
||
create_table :medias_operatingsystems , :id => false do |t|
|
||
t.references :media, :null => false
|
||
t.references :operatingsystem, :null => false
|
||
end
|
||
|
||
media_hash = Hash.new
|
||
Media.all.each do |medium|
|
||
unless medium.operatingsystem_id.nil?
|
||
os = Operatingsystem.find(medium.operatingsystem_id)
|
||
media_hash[os] = medium
|
||
if Operatingsystem.exists?(medium.operatingsystem_id)
|
||
os = Operatingsystem.find(medium.operatingsystem_id)
|
||
media_hash[os] = medium
|
||
else
|
||
say "skipped #{medium}"
|
||
end
|
||
end
|
||
end
|
||
|
||
create_table :medias_operatingsystems , :id => false do |t|
|
||
t.references :media, :null => false
|
||
t.references :operatingsystem, :null => false
|
||
end
|
||
|
||
media_hash.keys.each { |os| os.medias << media_hash[os] }
|
||
|
||
remove_column :medias, :operatingsystem_id
|
Also available in: Unified diff
migration might fail if medium does not have an opeartingsystem - refs #236