26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/enju_circulation/item.rb', line 26
def enju_circulation_item_model
include InstanceMethods
has_many :reserves, :foreign_key => :manifestation_id
scope :for_checkout, ->(identifier_conditions = 'item_identifier IS NOT NULL') {
includes(:circulation_status, :use_restriction).where(
'circulation_statuses.name' => FOR_CHECKOUT_CIRCULATION_STATUS,
'use_restrictions.name' => FOR_CHECKOUT_USE_RESTRICTION
).where(identifier_conditions)
}
scope :removed, -> { includes(:circulation_status).where('circulation_statuses.name' => 'Removed') }
has_many :checkouts
has_many :reserves
has_many :checked_items
has_many :baskets, :through => :checked_items
belongs_to :circulation_status, :validate => true
belongs_to :checkout_type
has_many :lending_policies, :dependent => :destroy
has_one :item_has_use_restriction, :dependent => :destroy
has_one :use_restriction, :through => :item_has_use_restriction
validates_associated :circulation_status, :checkout_type
validates_presence_of :circulation_status, :checkout_type
searchable do
string :circulation_status do
circulation_status.name
end
end
accepts_nested_attributes_for :item_has_use_restriction
before_update :delete_lending_policy
end
|