supplier improvements
This commit is contained in:
+9
-2
@@ -23,8 +23,7 @@ class List
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
view :by_supplier_id, key: :supplier_id
|
||||
view :for_supplier_view, key: [:supplier_id, :created_at]
|
||||
view :for_supplier_view, key: [:supplier_id, :state, :created_at]
|
||||
|
||||
view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
@@ -75,6 +74,14 @@ class List
|
||||
list
|
||||
end
|
||||
|
||||
def self.for_supplier(supplier, options = {})
|
||||
total_entries = database.view(for_supplier_view({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: false, reduce: true, descending: true}))
|
||||
options[:total_entries] = total_entries
|
||||
with_pagination_options(options) do |options|
|
||||
database.view(for_supplier_view({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: true, reduce: false, descending: true}.merge(options)))
|
||||
end
|
||||
end
|
||||
|
||||
def self.active_for_supplier(supplier_id, options = {})
|
||||
database.view(active_by_supplier_id_view(key: supplier_id, reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user