J'ai ajouté hstore_translate à un projet Rails4 avec des données existantes.hstore_translate migration de données existante
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
Comment puis-je accéder à mes anciens champs de sous-titres et de description? Parce que Post.subtitle et Post.description sont toujours nuls. La solution de repli ne fonctionne pas ou j'ai besoin de migrer les données en premier?
UPD:
Cette migration résout le problème.
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