TypeError: 123 is not a string when using options[:last] with group_by_duration
tallytarik opened this issue · comments
First off, thanks for an amazing gem, and even more thanks for your work on group_by_duration
- it's just what I needed for a project of mine!
I've come across an issue - if you try to use last:
with group_by_duration
, the following error is thrown:
TypeError: <number> is not a symbol nor a string
[..]/groupdate/lib/groupdate/series_builder.rb:154:in `respond_to?'
[..]/groupdate/lib/groupdate/series_builder.rb:154:in `time_range'
[..]/groupdate/lib/groupdate/magic.rb:74:in `time_range'
[..]/groupdate/lib/groupdate/magic.rb:175:in `generate_relation'
[..]/groupdate/lib/groupdate/query_methods.rb:20:in `group_by_duration'
[..]/groupdate/lib/groupdate/enumerable.rb:33:in `block in group_by_duration'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:398:in `block in scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:773:in `_scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:398:in `scoping'
[..]/gems/activerecord-6.0.2.1/lib/active_record/associations/collection_proxy.rb:1101:in `scoping'
[..]/groupdate/lib/groupdate/enumerable.rb:33:in `group_by_duration'
Using, e.g. the following code:
MyModel
.group_by_duration(15.minutes, :created_at, last: 24, default_value: 0)
The problem is that time_range
doesn't check if the period is an Integer (as is the case when grouping by duration) when options[:last]
is provided.
Some code was added to handle this case in generate_series
. Adding the same code to time_range
solves the problem. PR coming.
Fixed in #234
Just fyi, decided to go a different direction to group by 15 minute intervals. See #23 (comment).