Update primary taxons migration - take more care in setting the default primary taxon

This commit is contained in:
Rohan Mitchell
2014-06-04 14:27:05 +10:00
parent d52c1fa5da
commit 1ccfc46e50

View File

@@ -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