The instance objects currently have circular references which means they cannot be parsed to JSON.
Sometimes you want to send a fetched object to a client, or store it in a key-value store for a session. With all of the extra instance methods this cannot be done.
I propose a "clean" method for instances that returns an object with only stuff you want. Something like this:
Model.prototype.clean = function () {
var cleanObj = {};
for (var prop in this) {
if (this.attributes.indexOf(prop) >= 0) {
cleanObj[prop] = this[prop];
}
}
return cleanObj;
}
So you can then do:
Person.find(33).on("success", function () {
res.send(person.clean());
}
The instance objects currently have circular references which means they cannot be parsed to JSON.
Sometimes you want to send a fetched object to a client, or store it in a key-value store for a session. With all of the extra instance methods this cannot be done.
I propose a "clean" method for instances that returns an object with only stuff you want. Something like this:
So you can then do: