开发者

globalize2 - create_translation_table! and options for columns

开发者 https://www.devze.com 2022-12-29 22:20 出处:网络
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 follow

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

精彩评论

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

关注公众号