Files
mozo-backend/app/models/table.rb
T
2013-01-17 09:15:42 +01:00

49 lines
1.1 KiB
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}
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
#validates_uniqueness_of :number
view :by_number, key: :number
def occupied?
return @is_occupied if instance_variable_defined?(:'@is_occupied')
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
end
def active_list
@active_list ||= self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end
def reserved?
false
end
def name
number
end
# Method returning the sections table width
def width
2.0
end
# Method returning the sections table height
def height
2.0
end
end