Module: Ixtlan::Core::ActiveRecord

Defined in:
lib/ixtlan/core/active_record.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ixtlan/core/active_record.rb', line 5

def self.included(base)
  base.class_eval do

    def self.optimistic_find(updated_at, *args)
      if updated_at
        updated_at_date = new(:updated_at => updated_at).updated_at
        # try different ways to use the date
        # TODO maybe there is a nicer way ??
        first(:conditions => ["id = ? and updated_at <= ? and updated_at >= ?", args[0], updated_at, updated_at_date - 0.001]) || first(:conditions => ["id = ? and updated_at <= ? and updated_at >= ?", args[0], updated_at_date, updated_at_date - 0.001])
        # TODO make it work with different PKs
      end
    end

  end
end