Sha256: 516201b7142e31e53ed557e8cee86e687aa4c9ad6fa70e3ba1b0952e98dbfb83

Contents?: true

Size: 864 Bytes

Versions: 6

Compression:

Stored size: 864 Bytes

Contents

class Withdraw < ApplicationRecord
  belongs_to :basket
  belongs_to :item, touch: true
  belongs_to :librarian, class_name: 'User'

  validates :item_id,
    uniqueness: true, #{ message: I18n.t('withdraw.already_withdrawn', locale: I18n.default_locale) },
    presence: true #, { message: I18n.translate('withdraw.item_not_found', locale: I18n.default_locale) }
  validates_presence_of :basket_id
  validate :check_item

  attr_accessor :item_identifier

  paginates_per 10

  def check_item
    errors.add(:item) if item.try(:rent?)
    errors.add(:item) if item.try(:reserved?)
  end
end

# == Schema Information
#
# Table name: withdraws
#
#  id           :integer          not null, primary key
#  basket_id    :integer
#  item_id      :integer
#  librarian_id :integer
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enju_library-0.4.0.beta.4 app/models/withdraw.rb
enju_library-0.4.0.beta.3 app/models/withdraw.rb
enju_library-0.4.0.beta.2 app/models/withdraw.rb
enju_library-0.4.0.beta.1 app/models/withdraw.rb
enju_library-0.3.5 app/models/withdraw.rb
enju_library-0.3.4 app/models/withdraw.rb