Skip to content

Clean instance #73

Description

@mjadobson

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());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions