Class: ActiveRecord::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_data_owner/migration.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_data_owner_for(table_name, *args) ⇒ Object Also known as: data_owner



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/acts_as_data_owner/migration.rb', line 4

def acts_as_data_owner_for(table_name, *args)
  options = args.extract_options!
  fields  = [:creator, :owner, :updater]
  fields += [options[:include]].flatten if options[:include]
  fields -= [options[:exclude]].flatten if options[:exclude]
  prefix  = options[:prefix]            if options[:prefix]
  #Add fields to table
  change_table table_name do |t|
    fields.each do |f|
      t.references(f)
    end
  end

  #Add indexes
  fields.each do |f|
    add_index table_name, "#{f}_id",:name=>(prefix ? "#{prefix}_#{f}" : "index_#{table_name}_on_#{f}" )
  end
end