Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Globalize3 gem: How do I add an additional field to the translation table using a migration?

The docs for the Globalize3 gem are clear about how to create a translation table, but I don't see any information about how to add a field to a translation table during a later migration. For example, I initially included Category.create_translation_table! :name => :string when I created my Category model. Now, however, I need to add a translated field to the model.

How do I do that with a Rails migration? I don't see any docs for an alter_translation_table! method or anything similar...

like image 491
Clay Avatar asked Oct 12 '11 15:10

Clay


1 Answers

You can do it by hand, something like the following:

class AddNewFieldToYourTable < ActiveRecord::Migration
  def self.up
    change_table(:your_tables) do |t|
      t.string :new_field
    end
    change_table(:your_table_translations) do |t|
      t.string :new_field
    end
  end

  def self.down
    remove_column :your_tables, :new_field
    remove_column :your_table_translations, :new_field
  end
end
like image 92
user630522 Avatar answered Sep 20 '22 16:09

user630522