Skip to content

Commit

Permalink
Merge pull request #281 from tomatoes-app/update-date-time-types
Browse files Browse the repository at this point in the history
Update date time types
  • Loading branch information
potomak committed Mar 21, 2017
2 parents eac547d + f4dcdca commit 27811f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/models/concerns/expiring.rb
@@ -1,7 +1,9 @@
module Expiring
extend ActiveSupport::Concern

included do
field :eat, as: :expires_at, type: Time

index({ eat: 1 }, expire_after_seconds: 0, name: 'expiration_index')
end
end
15 changes: 13 additions & 2 deletions app/models/concerns/score.rb
@@ -1,10 +1,21 @@
module Score
extend ActiveSupport::Concern

included do
include Mongoid::Timestamps

belongs_to :user, foreign_key: :uid

field :s, as: :score, type: Integer
field :cat, as: :created_at, type: DateTime
field :uat, as: :updated_at, type: DateTime

# Note: `Mongoid::Timestamps` module defines `created_at`, `updated_at`,
# and callbacks to keep these fields up to date. `::fields` is a hash table
# that contains document's fields. This is a similar approach used by
# `Mongoid::Timestamps::Short` to define short names for timestamp fields.
fields.delete('created_at')
field :cat, as: :created_at, type: Time
fields.delete('updated_at')
field :uat, as: :updated_at, type: Time

index({ uid: 1 }, unique: true, name: 'uid_index')
index({ s: -1 }, name: 'score_index')
Expand Down

0 comments on commit 27811f7

Please sign in to comment.