-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Automattic/mongoose
- Loading branch information
Showing
27 changed files
with
448 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Set a populated virtual value on a document's `$$populatedVirtuals` value | ||
* | ||
* @param {*} populatedVirtuals A document's `$$populatedVirtuals` | ||
* @param {*} name The virtual name | ||
* @param {*} v The result of the populate query | ||
* @param {*} options The populate options. This function handles `justOne` and `count` options. | ||
* @returns {Array<Document>|Document|Object|Array<Object>} the populated virtual value that was set | ||
*/ | ||
|
||
module.exports = function setPopulatedVirtualValue(populatedVirtuals, name, v, options) { | ||
if (options.justOne || options.count) { | ||
populatedVirtuals[name] = Array.isArray(v) ? | ||
v[0] : | ||
v; | ||
|
||
if (typeof populatedVirtuals[name] !== 'object') { | ||
populatedVirtuals[name] = options.count ? v : null; | ||
} | ||
} else { | ||
populatedVirtuals[name] = Array.isArray(v) ? | ||
v : | ||
v == null ? [] : [v]; | ||
|
||
populatedVirtuals[name] = populatedVirtuals[name].filter(function(doc) { | ||
return doc && typeof doc === 'object'; | ||
}); | ||
} | ||
|
||
return populatedVirtuals[name]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.