Class: CreateTaxonomies

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/active_content/templates/taxonomy.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/active_content/templates/taxonomy.rb', line 2

def change
  create_table :taxonomies do |t|
    t.string :type
    t.string :name, null: false
    t.text   :description
    t.string :ancestry

    t.timestamps
  end

  add_index :taxonomies, :ancestry

  create_table :taxonomizations do |t|
    t.string     :field, null: false
    t.references :taxonomy
    t.references :taxonomizable, null: false, polymorphic: true, index: false

    t.timestamps
  end

  add_index :taxonomizations, [:taxonomizable_id, :taxonomizable_type, :taxonomy_id, :field], unique: true, name: :index_taxonomizations_on_taxonomizable_attribute
end