开发者

globalize2 - create_translation_table! and options for columns

could yo开发者_如何学Pythonu tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null => false, :default => "abc" ???


TRY Something like following

Post.create_translation_table! :title => :string, :text => :text, {:null=>false, :default=>"abc"}


Here is the method definition in the current version of globalize2:

  def create_translation_table!(fields)
    translated_attribute_names.each do |f|
      raise MigrationMissingTranslatedField, "Missing translated field #{f}" unless fields[f]
    end

    fields.each do |name, type|
      if translated_attribute_names.include?(name) && ![:string, :text].include?(type)
        raise BadMigrationFieldType, "Bad field type for #{name}, should be :string or :text"
      end
    end

    self.connection.create_table(translation_table_name) do |t|
      t.references table_name.sub(/^#{table_name_prefix}/, "").singularize
      t.string :locale
      fields.each do |name, type|
        t.column name, type
      end
      t.timestamps
    end

    self.connection.add_index(
      translation_table_name, 
      "#{table_name.sub(/^#{table_name_prefix}/, "").singularize}_id",
      :name => translation_index_name
    )
  end

As you can see, there is no third parameter passed to the t.column declarations. Therefore globalize2 will not support this without a patch.

My suggestion is just to manually create the migration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜