implement joining table

This commit is contained in:
2012-08-30 18:32:30 +02:00
parent 6696992320
commit aa0821d0ae
15 changed files with 228 additions and 35 deletions
+5 -7
View File
@@ -16,15 +16,13 @@ class Table
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?
@is_occupied = !self.class.database.view(List.active_by_table_id(key: id, reduce: true)).zero?
end
def active_list
@active_list ||= self.class.database.view(List.active_by_table_id(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
end
def reserved?