-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update settings OBO uniqueness validations #443
Conversation
@@ -27,6 +27,6 @@ def destroy_with_box? | |||
|
|||
def validate_box(box) | |||
box.errors.add(:settings_obo, :not_allowed) if obo.present? | |||
box.errors.add(:settings_obo, :invalid) if boxes.where.not(id: box.id).where("settings ->> 'obo' = ?", box.settings_obo).exists? | |||
box.errors.add(:settings_obo, :invalid) if boxes.where.not(id: box.id).map { |b| b.settings_obo.to_s }.include?(box.settings_obo.to_s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu som skor za to, ze upravme tu logiku ze prazdny string nedovolime a bude tam vzdy nil lebo akonahle povolime prazdny string tak sa tato podmienka rozlezie aj vsade inde. Musime cistit data najskor ako sa len daju.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vid koment
# Conflicts: # db/schema.rb
# Conflicts: # db/schema.rb
# Conflicts: # db/schema.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neviem ci sme rails 7.1 ale toto mi pride ako dobry fix https://edgeapi.rubyonrails.org/classes/ActiveRecord/Normalization.html
Sme 7.1, upravila som trochu @jsuchal |
class UpdateEmptyStringsBoxesSettingsObo < ActiveRecord::Migration[7.1] | ||
def up | ||
Upvs::Box.find_each do |box| | ||
box.update(settings_obo: (box.settings_obo.present? ? box.settings_obo : nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu to vies asi urobit aj jednou query co si vypyta prazdny string ale good enough
Tu sa ukazala potreba upravit trochu query kvoli tomu, ze mame rozne pripady, obo moze byt bud nil alebo aj prazdny string a podobne a potom to nezafungovalo. Bud teda takto upravme query alebo mozeme nejako skusit upratat, aby sme tie rozne tvary prazdneho obo odstranili.