Skip to content

Models that fail a save to the DB still save to the cache #78

Description

@robseward

Hi, I'm not sure if this is by design or not, but I noticed if a model fails validation during save, it is still saved to the cache. I'm using postgres.

Model definition

module.exports = function(db){
    var Project = db.define("projects", {
        name      : String,
        created   : Date,
        project_status  : ['active', 'completed', 'on hold', 'dropped']
    }, {
        methods: {
        },
        validations: {
            project_status: orm.validators.insideList([ 'active', 'completed', 'on hold', 'dropped' ], "Invalid Status")
        },
        cache: true
    });

    Project.hasOne('user');
    return Project;
};

Save an invalid value to the model.

Project.get(1, function(err, project){
            project.project_status = 'foo';
            project.save(function(err){

//This will print a validation error
                console.log(err);
            });

        });

Later, retrieving the model will print the invalid value.

Project.get(1, function(err, project){
            //This will print 'foo'
            console.log(project.project_status); 
        });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions