Skip to content

Update items fail on remapped column - instance from find method #509

Description

@hkbenchan

Node version: 0.10.25
orm version: 2.1.14
mysql version: 2.3.0

Reproduce of the bug:

Create a model that has a key with mapsTo enable, e.g.

var Model = db.define('model', {
    name: String,
    remapKey: { type: "integer", mapsTo: "remap_key", key: true }
});;

Later, when save an item that is gotten from Model.find(),

modelObject.name = "another value";
modelObject.save(function (err) {
    if (err) throw err;
    cb();
}

it will throw an error on mysql level, error message as follow

ER_BAD_FIELD_ERROR: Unknown column 'remapKey' in 'where clause'

Could you please help on fixing this?


Updated on 11:06 am Monday, 26 May, 2014 (GMT)

P.S. The error "ER_BAD_FIELD_ERROR" is gone when I define my model like this

var Model = db.define('model', {
    name: String,
    remapKey: { type: "integer", mapsTo: "remap_key" }
}, {
    id: "remap_key"
});;

But the update is not success as I lookup the query, it says

UPDATE `model` SET `name` = \'another value\', `remap_key` = 1 WHERE `remap_key` IS NULL

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions