I've added hstore_translate to a Rails4 project with existing data.
class Product < ActiveRecord::Base
translates :subtitle, :description
end
config.i18n.fallbacks = true
class AddTranslationColumnsToProducts < ActiveRecord::Migration
def change
add_column :products, :subtitle_translations, :hstore
add_column :products, :description_translations, :hstore
end
end
How can I access my old subtitle and description fields? Because now Post.subtitle and Post.description always nil. Fallback doesn't work or I need migrate data first?
upd:
This migration solves problem.
class MigrateExistingDataToTranslations < ActiveRecord::Migration
def change
execute "UPDATE products p SET subtitle_translations=hstore('en',(select subtitle from products where id = p.id));"
execute "UPDATE products p SET description_translations=hstore('en', (select description from products where id = p.id));"
end
end