dmfay / massive-js

A data mapper for Node.js and PostgreSQL.
2.49k stars 158 forks source link

db.table.Save() - Inserting array with composite primary key fails (but used to work) #536

Closed gpierrick closed 6 years ago

gpierrick commented 6 years ago

Table userId conversationId read deleted

This works

return postgres.db.participants.insert(data).then((res) => {
                return resolve(res);
            }).catch((err) => {
                logger.error(err);
                return reject(err);
            });

This doesn't

return postgres.db.participants.save(data).then((res) => {
                return resolve(res);
            }).catch((err) => {
                logger.error(err);
                return reject(err);
            });

It used to work in a previous version (I have one API running the old version of massivejs)

Error message Must provide an object with all fields being modified and the primary key if updating

dmfay commented 6 years ago

I notice you're inserting data[0] but saving data -- is that correct? Can you provide sample data?

gpierrick commented 6 years ago

Oops sorry it's meant to be data - also I have just tried insert and that works save doesn't


[{ userId: 1, conversationId: 2, read: true, deleted: false },{ userId: 2, conversationId: 2, read: true, deleted: false }]
dmfay commented 6 years ago

The error message you received is consistent with passing an array or thing-other-than-an-object to save, and that check goes back past 3.1.0. Please provide sample data which triggers the error on save.

gpierrick commented 6 years ago

I am still using 2.7.2 on my other project that's probably why.

dmfay commented 6 years ago

You can only save one object at a time -- it doesn't handle arrays.