24 lines
572 B
Ruby
24 lines
572 B
Ruby
class Table
|
|
include SimplyStored::Couch
|
|
|
|
property :number, type: Fixnum, default: 1
|
|
|
|
belongs_to :supplier
|
|
has_many :lists
|
|
|
|
validates :supplier_id, presence: true
|
|
#validates :list_id, presence: true
|
|
validates :number, numericality: {greater_than: 0}
|
|
|
|
view :active_lists, type: :custom, map_function: %|function(doc){
|
|
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
|
emit(doc._id, 1);
|
|
}
|
|
}|, reduce_function: '_sum'
|
|
|
|
def occupied?
|
|
not self.class.database.view(self.class.active_lists(key: list_id, reduce: true)).zero?
|
|
end
|
|
|
|
end
|