@@ -288,7 +288,8 @@ class @Minimongoid
288
288
if @_debug
289
289
console .info " --- WHERE ---"
290
290
console .info " #{ _ .singularize _ .classify @ to_s ()} .where(#{ JSON .stringify selector}#{ if not _ .isEmpty options then ' ,' + JSON .stringify options else ' ' } )"
291
- result = @ modelize @ find (selector, options)
291
+ result = @ find (selector, options).fetch ()
292
+ result = Relation .new self, result...
292
293
result .setQuery selector
293
294
console .info " > found #{ result .length } " if @_debug and result
294
295
result
@@ -306,11 +307,16 @@ class @Minimongoid
306
307
if doc = @_collection .findOne (selector, options)
307
308
@ init doc
308
309
309
- @ all: (options ) ->
310
+ @ all: (options = {} ) ->
310
311
@ where ({}, options)
311
312
312
313
# this doesn't perform a fetch, just generates a collection cursor
313
314
@ find: (selector = {}, options = {}) ->
315
+ self = @
316
+ # ***Important!*** Transform all docs in the collection to be an instance of our model
317
+ unless options .transform
318
+ options .transform = (doc ) -> self .init (doc)
319
+
314
320
# unless you just pass an id, in which case it *does* fetch the first
315
321
unless typeof selector == ' object'
316
322
if @_object_id
@@ -341,6 +347,7 @@ class @Minimongoid
341
347
342
348
343
349
# run a model init on all items in the collection
350
+ # -- somewhat deprecated -- used to be used in @where function, which is replaced by the transform inside of @find
344
351
@ modelize: (cursor , parent = null ) ->
345
352
self = @
346
353
models = cursor .map (i) -> self .init (i, parent)
0 commit comments