Revert adapter serialization. Remove geo point distance indicator.

This commit is contained in:
Ritchie Martori 2013-07-01 13:16:51 -07:00
parent e6a88ac254
commit dbd5efed50
6 changed files with 30 additions and 4 deletions

View File

@ -86,9 +86,25 @@ Memory.prototype.destroy = function destroy(model, id, callback) {
Memory.prototype.fromDb = function(model, data) {
if (!data) return null;
data = JSON.parse(data);
var ctor = this._models[model].model;
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) {

View File

@ -364,7 +364,8 @@ DataAccessObject.find = function find(params, cb) {
this.schema.adapter.all(this.modelName, params, function (err, data) {
if (data && data.forEach) {
data.forEach(function (d, i) {
var obj = new constr(d);
var obj = new constr;
obj._initProperties(d, false);
if (params && params.include && params.collect) {
data[i] = obj.__cachedRelations[params.collect];
} else {

View File

@ -60,7 +60,6 @@ exports.filter = function (arr, filter) {
// dont add
} else {
distances[obj.id] = d;
loc.distance = d;
result.push(obj);
}
});

View File

@ -15,6 +15,14 @@ function List(data, type, parent) {
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;
Object.defineProperty(list, 'parent', {

View File

@ -35,6 +35,7 @@ describe('datatypes', function() {
});
function testFind(next) {
debugger;
Model.findById(id, function(err, m) {
should.not.exist(err);
should.exist(m);

View File

@ -196,6 +196,7 @@ describe('relations', function() {
Article.create(function(e, article) {
article.tags.create({name: 'popular'}, function(e, t) {
t.should.be.an.instanceOf(Tag);
console.log(t);
ArticleTag.findOne(function(e, at) {
should.exist(at);
at.tagId.toString().should.equal(t.id.toString());