You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer: I'm not sure if this is a bug or I've misunderstood how this should work.
If I have a StockItem for a Variant and StockLocation, and I delete that StockItem, it remains in the database, due to acts_as_paranoid.
However, I can't re-create it, due to a uniqueness constraint: validates_uniqueness_of :variant_id, scope: :stock_location_id.
I see TaxCategory adds deleted_at to the scope, i.e. validates_uniqueness_of :variant_id, scope: [:stock_location_id, :deleted_at] ?
But I'm not sure that's right either, as undeleted stock items will have a NULL deleted_at, and NULL != NULL in SQL, so that uniqueness constraint will allow multiple undeleted products.
Steps to reproduce:
Add some stock to a variant in a given location
Delete that stock
Try and add some to stock to the same variant and the same location
ActiveRecord::RecordInvalid (Validation failed: Variant has already been taken)
Expected behaviour:
Able to add new stock without regard to stock that has been previously deleted
I've added this (horrible) workaround for the time being:
module Spree
StockItem.class_eval do
_validators.reject!{ |key, _| key == :variant_id }
_validate_callbacks.reject! do |callback|
callback.raw_filter.try(:attributes) == [:variant_id]
end
validates_uniqueness_of :variant_id, scope: [:stock_location_id, :deleted_at]
end
end
The text was updated successfully, but these errors were encountered:
Disclaimer: I'm not sure if this is a bug or I've misunderstood how this should work.
If I have a
StockItem
for aVariant
andStockLocation
, and I delete thatStockItem
, it remains in the database, due toacts_as_paranoid
.However, I can't re-create it, due to a uniqueness constraint:
validates_uniqueness_of :variant_id, scope: :stock_location_id
.I see TaxCategory adds
deleted_at
to the scope, i.e.validates_uniqueness_of :variant_id, scope: [:stock_location_id, :deleted_at]
?But I'm not sure that's right either, as undeleted stock items will have a NULL
deleted_at
, and NULL != NULL in SQL, so that uniqueness constraint will allow multiple undeleted products.Steps to reproduce:
ActiveRecord::RecordInvalid (Validation failed: Variant has already been taken)
Expected behaviour:
Versions:
Gemfile and stack trace: https://gist.github.com/steveh/6862586
I've added this (horrible) workaround for the time being:
The text was updated successfully, but these errors were encountered: