Skip to content

Commit

Permalink
Use Sequel Timestamps plugin to generated created_at and updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
dmac committed Aug 16, 2012
1 parent 85aeb12 commit c893de2
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions lib/db.rb
Expand Up @@ -2,19 +2,8 @@
require "pathological"
require "environment"

class Sequel::Model
def before_create
now = Time.now
self.created_at ||= now if self.columns.include?(:created_at)
self.updated_at = now if self.columns.include?(:updated_at)
super
end

def after_save
super
self.updated_at = Time.now if self.columns.include?(:updated_at)
end
end
# Timestamp all models with created_at and updated_at.
Sequel::Model.plugin :timestamps

DB = Sequel.postgres(:host => DB_HOST, :user => DB_USER, :password => DB_PASS, :database => DB_NAME)

Expand Down

0 comments on commit c893de2

Please sign in to comment.