simply_stored 0.1.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +1 -0
- data/lib/simply_stored/couch/belongs_to.rb +2 -2
- data/lib/simply_stored/instance_methods.rb +14 -3
- metadata +1 -1
data/CHANGELOG.md
CHANGED
@@ -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",
|
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}",
|
159
|
+
"association_#{from.to_s.singularize.underscore}_belongs_to_#{to.name.singularize.underscore}", view_options))
|
149
160
|
end
|
150
161
|
end
|
151
162
|
|