- 1
deals = Deal.joins(:deal_locations).select("deals.id, (SELECT array(SELECT category_id FROM deal_categories WHERE deal_id = deals.id ORDER BY category_id ASC)) AS category, deals.start_date, deals.end_date, deals.address, deals.theme, deals.alias, deals.metro, deals.district, deals.discount, deals.coupon_count, deals.issued_coupons, deals.main_image, count(*) OVER() AS total_count, trunc(abs(extract(epoch FROM age(deals.end_date, clock_timestamp()))/86400)) AS days_left").where("deal_locations.deal_id = deals.id AND deal_locations.location_id = ? AND deals.category_id IN (#{categories[0...-2]}) AND deals.id NOT IN (#{ex_deals.map{|e| e}.join(", ")})", params[:location].to_i).active.in_stock.limit(limit).offset(offset).order("deals.start_date desc")
Rails. Да, да, активрекорд, я помню о тебе.