Skip to content
New issue

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

Allow Relation#sum to take an init parameters #42190

Merged
merged 1 commit into from May 10, 2021

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented May 10, 2021

Ref: #41669 (comment)

This is needed to not prevent full use of Enumerable#sum on Relation objects.

Since #42080, if you are summing a list of objects that aren't Numeric, you need to provide an init value, e.g. products.sum(Money.new(0), &:price).

cc @pixeltrix @alberto-mota @rafaelfranca

@casperisfine casperisfine changed the title Allow Relation#sum to take an init paramaters Allow Relation#sum to take an init parameters May 10, 2021
@casperisfine
Copy link
Contributor Author

An issue with this is that Relation#sum is being reported as the source of the deprecation, which really isn't helpful for fixing it up.

No idea how to improve that though.

This is needed to not prevent full use of `Enumerable#sum`
on `Relation` objects.
@casperisfine
Copy link
Contributor Author

Ok, I've updated Relation#sum further to deal with the deprecation itself. This should make it easier for users to fix the deprecations.

@byroot byroot merged commit e538979 into rails:main May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants