simply_stored 0.1.15 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ Changelog
7
7
  Post.find(:all, :order => :desc)
8
8
 
9
9
  Default to the CouchDB default of ascending.
10
+ Please update ALL design documents!
10
11
 
11
12
 
12
13
  - Support :limit option to has_many and has_many :through associations, e.g:
@@ -10,7 +10,7 @@ module SimplyStored
10
10
  if (doc['#{soft_delete_attribute}'] && doc['#{soft_delete_attribute}'] != null){
11
11
  // "soft" deleted
12
12
  }else{
13
- emit(doc.#{name.to_s}_id, null);
13
+ emit([doc.#{name.to_s}_id, doc.created_at], null);
14
14
  }
15
15
  }
16
16
  }
@@ -31,7 +31,7 @@ module SimplyStored
31
31
  map_definition_with_deleted = <<-eos
32
32
  function(doc) {
33
33
  if (doc['ruby_class'] == '#{self.to_s}' && doc['#{name.to_s}_id'] != null) {
34
- emit(doc.#{name.to_s}_id, null);
34
+ emit([doc.#{name.to_s}_id, doc.created_at], null);
35
35
  }
36
36
  }
37
37
  eos
@@ -123,8 +123,14 @@ module SimplyStored
123
123
  def find_associated(from, to, options = {})
124
124
  view_options = {}
125
125
  view_options[:reduce] = false
126
- view_options[:key] = id
127
126
  view_options[:descending] = options[:descending] if options[:descending]
127
+ if view_options[:descending]
128
+ view_options[:startkey] = ["#{id}\u9999"]
129
+ view_options[:endkey] = [id]
130
+ else
131
+ view_options[:startkey] = [id]
132
+ view_options[:endkey] = ["#{id}\u9999"]
133
+ end
128
134
  view_options[:limit] = options[:limit] if options[:limit]
129
135
  if options[:with_deleted]
130
136
  CouchPotato.database.view(
@@ -138,14 +144,19 @@ module SimplyStored
138
144
  end
139
145
 
140
146
  def count_associated(from, to, options = {})
147
+ view_options = {}
148
+ view_options[:reduce] = true
149
+ view_options[:include_docs] = false
150
+ view_options[:startkey] = [id]
151
+ view_options[:endkey] = ["#{id}\u9999"]
141
152
  if options[:with_deleted]
142
153
  CouchPotato.database.view(
143
154
  self.class.get_class_from_name(from).send(
144
- "association_#{from.to_s.singularize.underscore}_belongs_to_#{to.name.singularize.underscore}_with_deleted", :key => id, :reduce => true, :include_docs => false))
155
+ "association_#{from.to_s.singularize.underscore}_belongs_to_#{to.name.singularize.underscore}_with_deleted", view_options))
145
156
  else
146
157
  CouchPotato.database.view(
147
158
  self.class.get_class_from_name(from).send(
148
- "association_#{from.to_s.singularize.underscore}_belongs_to_#{to.name.singularize.underscore}", :key => id, :reduce => true, :include_docs => false))
159
+ "association_#{from.to_s.singularize.underscore}_belongs_to_#{to.name.singularize.underscore}", view_options))
149
160
  end
150
161
  end
151
162
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_stored
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer, Jonathan Weiss