From 7c85026c4d58bd61b470d6bea47f3e31144f92b5 Mon Sep 17 00:00:00 2001 From: Jan Raasch <425211+janraasch@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:16:30 +0100 Subject: [PATCH] Filter unique amounts on the app level See https://github.com/joemasilotti/daily-log/issues/7#issue-2052365742 --- rails/app/models/water_entry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails/app/models/water_entry.rb b/rails/app/models/water_entry.rb index 040e774..0cf197f 100644 --- a/rails/app/models/water_entry.rb +++ b/rails/app/models/water_entry.rb @@ -5,7 +5,7 @@ class WaterEntry < ApplicationRecord belongs_to :user - scope :recent, -> { distinct(:amount).order(created_at: :desc).limit(3).sort_by(&:amount) } + scope :recent, -> { order(created_at: :desc).limit(3).uniq(&:amount_value).sort_by(&:amount) } scope :amounts, -> { map(&:amount).presence || [Measured::Volume.new(0, :oz)] } measured_volume :amount