39 lines
876 B
Ruby
39 lines
876 B
Ruby
class Table
|
|
include SimplyStored::Couch
|
|
|
|
property :number, type: Fixnum, default: 1
|
|
property :position_x, type: Float
|
|
property :position_y, type: Float
|
|
|
|
belongs_to :supplier
|
|
belongs_to :section
|
|
has_many :lists
|
|
|
|
attr_protected :supplier_id
|
|
|
|
validates :supplier_id, presence: true
|
|
#validates :list_id, presence: true
|
|
validates :number, numericality: {greater_than: 0}
|
|
validates_uniqueness_of :number
|
|
|
|
view :active_lists, type: :custom, map_function: %|function(doc){
|
|
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
|
emit(doc.table_id, 1);
|
|
}
|
|
}|, reduce_function: '_sum'
|
|
|
|
def occupied?
|
|
return @is_occupied if instance_variable_defined?(:'@is_occupied')
|
|
@is_occupied = !self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero?
|
|
end
|
|
|
|
def reserved?
|
|
false
|
|
end
|
|
|
|
def name
|
|
number
|
|
end
|
|
|
|
end
|