Sha256: 24ad5a4b9223c8318d3227003fcf98cb10db03b14052ebd7a94c408f80055664

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

class Basket < ApplicationRecord
  default_scope { order('baskets.id DESC') }
  scope :will_expire, lambda {|date| where('created_at < ?', date)}
  belongs_to :user, validate: true
  has_many :accepts
  has_many :withdraws

  validates_associated :user, on: :create
  # 貸出完了後にかごのユーザidは破棄する
  validates_presence_of :user, on: :create
  validate :check_suspended

  attr_accessor :user_number

  def check_suspended
    if user
      errors[:base] << I18n.t('basket.this_account_is_suspended') if user.locked_at
    else
      errors[:base] << I18n.t('user.not_found')
    end
  end

  def self.expire
    Basket.will_expire(Time.zone.now.beginning_of_day).destroy_all
    logger.info "#{Time.zone.now} baskets expired!"
  end
end

# == Schema Information
#
# Table name: baskets
#
#  id           :bigint           not null, primary key
#  user_id      :bigint
#  note         :text
#  lock_version :integer          default(0), not null
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enju_library-0.4.0.rc.1 app/models/basket.rb