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