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
+8
View File
@@ -5,6 +5,8 @@ class List
property :needs_help, type: :boolean, default: false
property :needs_payment, type: :boolean, default: false
property :closed_at, type: Time
property :join_requests, type: Array, default: []
has_many :orders, dependent: :destroy
belongs_to :table
belongs_to :supplier
@@ -16,6 +18,12 @@ class List
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
view :active_by_table_id, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.table_id, 1);
}
}|, reduce_function: '_sum'
def self.from_table table, user
return if user.has_active_list?
list = new table: table, supplier_id: table.supplier_id, section_id: table.section_id