implement joining table
This commit is contained in:
+5
-7
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user