Skip to content

Commit

Permalink
Fixed duplicate key sql error by preventing reporting_period from doi…
Browse files Browse the repository at this point in the history
…ng a time zone conversion.

Signed-off-by: Marco Otte-Witte <marco.otte-witte@simplabs.com>
  • Loading branch information
myronmarston authored and marcoow committed May 4, 2009
1 parent 8791b1e commit fa8af89
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/simplabs/reports_as_sparkline/report_cache.rb
Expand Up @@ -8,6 +8,13 @@ class ReportCache < ActiveRecord::Base

set_table_name :reports_as_sparkline_cache

# When reporting_period has a time zone conversion performed, we get duplicate key sql errors.
# This occurs because find_cached_data will return a record set that is missing a record when we
# have an end date. The SQL criteria reporting_period BETWEEN before_date AND end_date will not include
# the last record that it should, because our end_date will not be time-zone converted (ex: 5/1/09 00:00:00) but
# the reported_period in the database will be time-zone converted (ex: 5/1/00 07:00:00).
self.skip_time_zone_conversion_for_attributes = [:reporting_period]

def self.process(report, options, cache = true, &block) #:nodoc:
raise ArgumentError.new('A block must be given') unless block_given?
self.transaction do
Expand Down

0 comments on commit fa8af89

Please sign in to comment.