From 1ccfc46e50bbf8f1b0b4fc69f699b7a50cedd072 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 4 Jun 2014 14:27:05 +1000 Subject: [PATCH] Update primary taxons migration - take more care in setting the default primary taxon --- db/migrate/20140522044009_add_primary_taxon_to_products.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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