-
Notifications
You must be signed in to change notification settings - Fork 191
Closed
Description
Description
Hi! Thanks for this gem - it has been a go-to for readonly data in our projects.
We ran into an issue in our application where calling count with a block on a relation returned the count of elements in the relation, not the count of elements for which the block returns true.
Would it be possible for count to fallback to Enumerable#count if given a block? Rails introduced this in 5.1 for ActiveRecord::Relation and I think it'd made sense for ActiveHash::Relation to behave the same.
Code to Reproduce
class Example < ActiveHash::Base
self.data = [
{ id: 1, active: true },
{ id: 2, active: true },
{ id: 3, active: false }
]
end
Example.count
# 3
Example.count { |e| e.active }
# 3
Example.all.to_a.count { |e| e.active }
# 2
# Desired behavior:
# Example.count { |e| e.active }
# 2Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels