diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index 28c27f820f..d985d7f1b8 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -6,7 +6,9 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id Spree::Product.all.each do |p| - p.update_column :primary_taxon_id, (p.taxons.first || Spree::Taxon.first) + primary_taxon = p.taxons.where('spree_taxons.name != ?', 'specials').first + first_taxon = Spree::Taxonomy.find_by_name('Products').andand.root || Spree::Taxon.first + p.update_column :primary_taxon_id, (primary_taxon || first_taxon) end change_column :spree_products, :primary_taxon_id, :integer, null: false