supplier improvements

This commit is contained in:
2013-03-09 14:18:21 +01:00
parent 730f910881
commit cc13797f5a
53 changed files with 819 additions and 156 deletions
+9 -2
View File
@@ -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