mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Update primary taxons migration - take more care in setting the default primary taxon
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user