I want check the availability of my Offer with her bookings,
I tried with this scope:
My model:
scope :booking_available, -> (arrival_date, departure_date) {
joins(:bookings).where.not('bookings.arrival_date <= ? AND bookings.departure_date >= ? AND bookings.status != ?', arrival_date, departure_date, 0)
}
But i got all offers in my search result duplicate by the number of bookings checked,
I tried to add .distinct at the end of the scope but when i use other search params i got error PG::UndefinedFunction: ERROR: could not identify an equality operator for type json similar to this error
I would like know how my availability param can work with other search params ?
My controller:
if offer_params[:arrival_date].present? && offer_params[:departure_date].present?
@offers = @offers.booking_available(offer_params[:arrival_date], offer_params[:departure_date])
end
@offers = @offers
.page(params[:page])
.per(60)
respond_to do |format|
format.json { render template: 'offers/v2/search', status: :ok }
end
How i render offers in my view:
json[:offers] = @offers.map do |offer|
end
how my availability param can work with other search params ?orI tried to add .distinct at the end of the scope but when i use other search params i got error?how my availability param can work with other search params ?