We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi (again) 😁😇,
while working on #2 / #6 I realised that the distinct(:amount)-call in WaterEntry
distinct(:amount)
WaterEntry
daily-log/rails/app/models/water_entry.rb
Line 8 in 510e142
does not actually do anything. Here's a link to the documentation: https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-distinct. The method signature of distinct is very misleading I think 😅.
distinct
Add a couple of WaterEntry-items with the same value:
IMHO the simplest thing would be do take care of uniqueness (and sorting - #2) after loading the latest three items into the application, i.e.
scope :recent, -> { order(created_at: :desc).limit(3).to_a.uniq(&:amount_value) }
or
scope :recent, -> { order(created_at: :desc).limit(3).to_a.uniq { |wi| wi.amount.value } }
Then, #2 could be solved by appending .sort_by(:amount).
.sort_by(:amount)
The text was updated successfully, but these errors were encountered:
Ha, I should have read this first before addressing your other PR! 😆
This still won't work if the last 2 entries are the same because we are querying for 3 before grabbing unique entries.
I'm going to close this in favor of the PR you opened since that now has a failing test.
Sorry, something went wrong.
Filter unique amounts on the app level
7c85026
See joemasilotti#7 (comment)
No branches or pull requests
Hi (again) 😁😇,
while working on #2 / #6 I realised that the
distinct(:amount)
-call inWaterEntry
daily-log/rails/app/models/water_entry.rb
Line 8 in 510e142
does not actually do anything. Here's a link to the documentation: https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-distinct. The method signature of
distinct
is very misleading I think 😅.How to reproduce
Add a couple of
WaterEntry
-items with the same value:Idea 4 a Fix
IMHO the simplest thing would be do take care of uniqueness (and sorting - #2) after loading the latest three items into the application, i.e.
or
Then, #2 could be solved by appending
.sort_by(:amount)
.The text was updated successfully, but these errors were encountered: