Merge pull request #387 from fabien/fix/coerce
Don't coerce nested objects into Model instances
This commit is contained in:
commit
f1bdf50e2a
|
@ -21,6 +21,7 @@ var setScopeValuesFromWhere = utils.setScopeValuesFromWhere;
|
||||||
var mergeQuery = utils.mergeQuery;
|
var mergeQuery = utils.mergeQuery;
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
var BaseModel = require('./model');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all persistent objects.
|
* Base class for all persistent objects.
|
||||||
|
@ -593,6 +594,10 @@ DataAccessObject._coerce = function (where) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DataType.prototype instanceof BaseModel) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (DataType === geo.GeoPoint) {
|
if (DataType === geo.GeoPoint) {
|
||||||
// Skip the GeoPoint as the near operator breaks the assumption that
|
// Skip the GeoPoint as the near operator breaks the assumption that
|
||||||
// an operation has only one property
|
// an operation has only one property
|
||||||
|
|
|
@ -7,13 +7,16 @@ describe('datatypes', function () {
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
db = getSchema();
|
db = getSchema();
|
||||||
|
Nested = db.define('Nested', {});
|
||||||
|
|
||||||
Model = db.define('Model', {
|
Model = db.define('Model', {
|
||||||
str: String,
|
str: String,
|
||||||
date: Date,
|
date: Date,
|
||||||
num: Number,
|
num: Number,
|
||||||
bool: Boolean,
|
bool: Boolean,
|
||||||
list: {type: [String]},
|
list: {type: [String]},
|
||||||
arr: Array
|
arr: Array,
|
||||||
|
nested: Nested
|
||||||
});
|
});
|
||||||
db.automigrate(function () {
|
db.automigrate(function () {
|
||||||
Model.destroyAll(done);
|
Model.destroyAll(done);
|
||||||
|
@ -114,4 +117,10 @@ describe('datatypes', function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not coerce nested objects into ModelConstructor types', function() {
|
||||||
|
var coerced = Model._coerce({ nested: { foo: 'bar' } });
|
||||||
|
coerced.nested.constructor.name.should.equal('Object');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue