Chris@1517: class DeleteOrphanTimeEntriesCustomValues < ActiveRecord::Migration Chris@1517: def up Chris@1517: CustomValue.where("customized_type = ? AND NOT EXISTS (SELECT 1 FROM #{TimeEntry.table_name} t WHERE t.id = customized_id)", "TimeEntry").delete_all Chris@1517: end Chris@1517: Chris@1517: def down Chris@1517: # nop Chris@1517: end Chris@1517: end