Skip to content

Commit

Permalink
Use unscoped when create stock items in migration
Browse files Browse the repository at this point in the history
By the time the migration runs the default scope with deleted_at was
already defined so mocking acts_as_paranoid doesn't make any difference

related to spree#3805
  • Loading branch information
huoxito committed Oct 11, 2013
1 parent 61b1d2d commit 7996428
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions core/db/migrate/20130213191427_create_default_stock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ def up
location = Spree::StockLocation.new(name: 'default')
location.save(validate: false)

Spree::StockItem.class_eval do
# Column name check here for #3805
unless column_names.include?("deleted_at")
def self.acts_as_paranoid; end
end
end

Spree::Variant.all.each do |variant|
stock_item = location.stock_items.build(variant: variant)
stock_item = Spree::StockItem.unscoped.build(stock_location: location, variant: variant)
stock_item.send(:count_on_hand=, variant.count_on_hand)
stock_item.save!
# Avoid running default_scope defined by acts_as_paranoid, related to #3805,
# validations would run a query with a delete_at column tha might not be present yet
stock_item.save! validate: false
end

remove_column :spree_variants, :count_on_hand
Expand Down

0 comments on commit 7996428

Please sign in to comment.