Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upsert not working with models that have custom getters #2987

Closed
grahamb opened this issue Jan 22, 2015 · 2 comments
Closed

Upsert not working with models that have custom getters #2987

grahamb opened this issue Jan 22, 2015 · 2 comments
Assignees

Comments

@grahamb
Copy link

grahamb commented Jan 22, 2015

This might be a duplicate of #2946.

I have a model that has a few "virtual" fields implemented as getters. When I try to do an upsert on this model, it is attempting to set values on the getters, which causes Sequelize to get all sorts of cranky:

> Executing (default): CREATE OR REPLACE FUNCTION pg_temp.sequelize_upsert() 
RETURNS integer AS $$ BEGIN INSERT INTO "OOS" 
("certifications_na","previous_experience_na","recruited_by_na","oos_number","first_name","last_name",
"email","address","city","province","country","postal_code","phone","cell_phone","pre_recruited",
"recruited_by","previous_experience","certifications","dob","created_at","updated_at") VALUES (...); 
RETURN 1; EXCEPTION WHEN unique_violation THEN UPDATE "OOS" SET ... WHERE 
("oos_number"=173); RETURN 2; END; $$ LANGUAGE plpgsql; SELECT * FROM 
pg_temp.sequelize_upsert();

Possibly unhandled SequelizeDatabaseError: column "certifications_na" of relation "OOS" does not exist
    at module.exports.Query.formatError (/Users/grahamb/Dropbox/code/personal/pj/selection-app/node_modules/sequelize/lib/dialects/postgres/query.js:309:16)
    at null.<anonymous> (/Users/grahamb/Dropbox/code/personal/pj/selection-app/node_modules/sequelize/lib/dialects/postgres/query.js:64:21)
    at emit (events.js:95:17)
    at Query.handleError (/Users/grahamb/Dropbox/code/personal/pj/selection-app/node_modules/pg/lib/query.js:99:8)
    at null.<anonymous> (/Users/grahamb/Dropbox/code/personal/pj/selection-app/node_modules/pg/lib/client.js:166:26)
    at emit (events.js:95:17)
    at Socket.<anonymous> (/Users/grahamb/Dropbox/code/personal/pj/selection-app/node_modules/pg/lib/connection.js:109:12)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)

Sequelize 2.0.0rc8

@janmeier
Copy link
Member

janmeier commented Feb 3, 2015

There should probably be some kind of internal "get values for db" method which takes into account virtuals and renamed field. Could be usefull for #2860 as well

@edu791
Copy link

edu791 commented May 26, 2017

Is there any solution?
I got the same problem

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

No branches or pull requests

4 participants