Skip to content

onSave should be able to change the isNew state #88

@danyg

Description

@danyg

Hello, I don't know how to resolve with your ORM this MySql sentence (I'm using your ORM to connect to SQLITE and MySQL)

UPDATE ON KEY EXISTS

to do this, I use the onSave hook, and there I check if are a record with the Keys,

the code is something like this:

TypesDressStores.onSave = function(obj, connection, callback){
    if(!obj.id && !!obj.idStore && !!obj.idDressStore){
        TypesDressStores
            .using(connection)
            .where({
                idStore: obj._idStore,
                idDressStore: obj.idDressStore
            })
            .all(function(err, items){
                if(err) throw err;

                if(items.length === 0){
                    callback();
                }else if(items.length === 1){
                    obj.id = items[0];
                    callback(); // THE ISSUE IS HERE!
                }else{
                    throw 'To many matches!';
                }
            }

    }else{
        callback();
    }
};

I see that callback is defined in lib/connection.js:92 and check for a isNew variable received from save or update method
I think that callback must receive a parameter to force the update for this cases.

There is another way to do this?

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