Implemented modifier

pull/2/head
Louis Chatriot 12 years ago
parent 753035c0ef
commit 671539a614
  1. 17
      lib/model.js

@ -9,6 +9,7 @@ var dateToJSON = function () { return { $$date: this.getTime() }; }
, util = require('util')
, _ = require('underscore')
, modifierFunctions = {}
, lastStepModifierFunctions = {}
, comparisonFunctions = {}
, logicalOperators = {}
;
@ -213,6 +214,22 @@ function compareThings (a, b) {
// Updating documents
// ==============================================================
lastStepModifierFunctions.$set = function (obj, field, value) {
obj[field] = value;
};
function findLastModificationStep (modifier, obj, field, value) {
var fieldParts = typeof field === 'string' ? field.split('.') : field;
if (fieldParts.length === 1) {
lastStepModifierFunctions[modifier](obj, field, value);
} else {
obj[fieldParts[0]] = obj[fieldParts[0]] || {};
modifierFunctions[modifier](obj[fieldParts[0]], fieldParts.slice(1), value);
}
}
/**
* Set field to value in a model
* Create it if it doesn't exist

Loading…
Cancel
Save