NodeJS - Sequelize updating issue

relax4o

I have a problem with updating method.

I am doing this:

// Char is outside the object where update method is...
Char = db.define('characters', {}, {
    tableName: 'characters',
    updatedAt: false,
    createdAt: false
});

//... part of the whole object
update: function ( columns, callback ) {

    Char.update( columns, { where: { id: this.get('char_id') } } )
    .complete( function ( err, res ) {
        f.log(res, 'd');
    });
},

When I define updatedAt to be false, the updates stop working at all and I don't know how to prevent that, except to add a column in my database. It throws me "Query was empty". So I tried to define updatedAt as 'created_at' - an existing column in my table and then the updates have worked, but not at all. The query updating only 'created_at' with the timestamp, but not my preferred columns.

Example that I receive in the console:

Executing (default): UPDATE characters SET created_at='2015-02-03 21:03:00' WHERE id='1'

It should be:

Executing (default): UPDATE characters SET health = ..., created_at='2015-02-03 21:03:00' WHERE id='1'

I debug whether the columns parameter is valid parameter. Yes, it is - I send an object and receive an object.

Can someone help me. I tried old ways, new ways, read posts, but nothing.

EDIT: I found where I'm wrong. I should define all fields which I want to update/insert. Because of my english I didn't understand right the define function in documentation. I thought that when you define the fields you'll recreate your table structure, but now I realize, that that would happen if run sync() method.

relax4o

I found where I'm wrong. I should define all fields which I want to update/insert. Because of my english I didn't understand right the define function in documentation. I thought that when you define the fields you'll recreate your table structure, but now I realize, that that would happen if run sync() method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related