Revert adapter serialization. Remove geo point distance indicator.
This commit is contained in:
parent
e6a88ac254
commit
dbd5efed50
|
@ -86,9 +86,25 @@ Memory.prototype.destroy = function destroy(model, id, callback) {
|
||||||
Memory.prototype.fromDb = function(model, data) {
|
Memory.prototype.fromDb = function(model, data) {
|
||||||
if (!data) return null;
|
if (!data) return null;
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
var ctor = this._models[model].model;
|
|
||||||
var props = this._models[model].properties;
|
var props = this._models[model].properties;
|
||||||
return ctor(data);
|
Object.keys(data).forEach(function (key) {
|
||||||
|
var val = data[key];
|
||||||
|
if (typeof val === 'undefined' || val === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (props[key]) {
|
||||||
|
switch(props[key].type.name) {
|
||||||
|
case 'Date':
|
||||||
|
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||||
|
break;
|
||||||
|
case 'Boolean':
|
||||||
|
val = new Boolean(val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data[key] = val;
|
||||||
|
});
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
Memory.prototype.all = function all(model, filter, callback) {
|
Memory.prototype.all = function all(model, filter, callback) {
|
||||||
|
|
|
@ -364,7 +364,8 @@ DataAccessObject.find = function find(params, cb) {
|
||||||
this.schema.adapter.all(this.modelName, params, function (err, data) {
|
this.schema.adapter.all(this.modelName, params, function (err, data) {
|
||||||
if (data && data.forEach) {
|
if (data && data.forEach) {
|
||||||
data.forEach(function (d, i) {
|
data.forEach(function (d, i) {
|
||||||
var obj = new constr(d);
|
var obj = new constr;
|
||||||
|
obj._initProperties(d, false);
|
||||||
if (params && params.include && params.collect) {
|
if (params && params.include && params.collect) {
|
||||||
data[i] = obj.__cachedRelations[params.collect];
|
data[i] = obj.__cachedRelations[params.collect];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -60,7 +60,6 @@ exports.filter = function (arr, filter) {
|
||||||
// dont add
|
// dont add
|
||||||
} else {
|
} else {
|
||||||
distances[obj.id] = d;
|
distances[obj.id] = d;
|
||||||
loc.distance = d;
|
|
||||||
result.push(obj);
|
result.push(obj);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,14 @@ function List(data, type, parent) {
|
||||||
if (!(list instanceof List)) {
|
if (!(list instanceof List)) {
|
||||||
return new List(data);
|
return new List(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(typeof data === 'string') {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
} catch(e) {
|
||||||
|
throw new Error('could not create List from JSON string: ', data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data && data instanceof List) data = data.items;
|
if (data && data instanceof List) data = data.items;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ describe('datatypes', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function testFind(next) {
|
function testFind(next) {
|
||||||
|
debugger;
|
||||||
Model.findById(id, function(err, m) {
|
Model.findById(id, function(err, m) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
should.exist(m);
|
should.exist(m);
|
||||||
|
|
|
@ -196,6 +196,7 @@ describe('relations', function() {
|
||||||
Article.create(function(e, article) {
|
Article.create(function(e, article) {
|
||||||
article.tags.create({name: 'popular'}, function(e, t) {
|
article.tags.create({name: 'popular'}, function(e, t) {
|
||||||
t.should.be.an.instanceOf(Tag);
|
t.should.be.an.instanceOf(Tag);
|
||||||
|
console.log(t);
|
||||||
ArticleTag.findOne(function(e, at) {
|
ArticleTag.findOne(function(e, at) {
|
||||||
should.exist(at);
|
should.exist(at);
|
||||||
at.tagId.toString().should.equal(t.id.toString());
|
at.tagId.toString().should.equal(t.id.toString());
|
||||||
|
|
Loading…
Reference in New Issue