From a0d158974b8cfe63769290a4f21171e7ac26a089 Mon Sep 17 00:00:00 2001 From: Du Peng <gnepud@gmail.com> Date: Wed, 29 Jun 2022 19:58:53 +0200 Subject: [PATCH] fix bug: validator of reservation can't find if slot has reserved by reservable type --- CHANGELOG.md | 2 ++ app/models/cart_item/reservation.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9641a42b..d146a3a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## next deploy +- Fix a bug: validator of reservation can't find if slot has reserved by reservable type + ## v5.4.8 2022 June 29 - My reservations dashboard diff --git a/app/models/cart_item/reservation.rb b/app/models/cart_item/reservation.rb index 363a21da7..9f9909217 100644 --- a/app/models/cart_item/reservation.rb +++ b/app/models/cart_item/reservation.rb @@ -50,8 +50,8 @@ class CartItem::Reservation < CartItem::BaseItem end if availability.available_type == 'machines' - s = Slot.find_by(start_at: slot[:start_at], end_at: slot[:end_at], availability_id: slot[:availability_id], canceled_at: nil) - unless s.nil? + s = Slot.includes(:reservations).where(start_at: slot[:start_at], end_at: slot[:end_at], availability_id: slot[:availability_id], canceled_at: nil, "reservations.reservable": @reservable) + unless s.empty? @errors[:slot] = 'slot is reserved' return false end