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

Model named 'record' throws an error when inserting a new row through findOrCreate #10323

Open
craig-gordon opened this issue Jan 6, 2019 · 2 comments

Comments

@craig-gordon
Copy link

What are you doing?

Using Sequelize 5.0.0-beta.15, I am executing a simple findOrCreate query for a model named Record (table name 'record') that is creating a new table row. In every other permutation of this query there is no error.

  1. Finding an existing row in the 'record' table through findOrCreate() yields a normal result.
  2. Creating a new row in the 'record' table through create() yields a normal result.
  3. Creating a new row in a different table (example: 'document') through findOrCreate() yields a normal result.
const database = new Sequelize(/* options */, {
  define: {
    freezeTableName: true
  },
  /* other parameters */
});
const Record = database.define('record', {
  /* model attributes */
});

Record.belongsTo(Player);
Player.hasMany(Record);
Record.findOrCreate({where: {
  playerId: 1
  /* other parameters */
}});

What do you expect to happen?

Calling Record.findOrCreate() with data not yet in the database should return the [instance, created] promise like normal.

What is actually happening?

I receive this error:

Unhandled rejection SequelizeDatabaseError: PL/pgSQL functions cannot accept type record
    at Query.formatError (C:\Users\cyghf\Desktop\wrhistory\node_modules\sequelize\lib\dialects\postgres\query.js:376:16)
    at query.catch.err (C:\Users\cyghf\Desktop\wrhistory\node_modules\sequelize\lib\dialects\postgres\query.js:86:18)
    at tryCatcher (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\promise.js:689:18)
    at Async._drainQueue (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (C:\Users\cyghf\Desktop\wrhistory\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

Dialect: postgres
Dialect version: pg@^7.7.1 (also tested with pg@^7.4.3)
Database version: 10.4 (AWS RDS Engine version)
Sequelize version: 5.0.0-beta.15
Tested with latest release: Yes

@mubaidr
Copy link

mubaidr commented Jan 9, 2019

record is a built in variable for pgSQL databases. You need to use other model name.

@sushantdhiman
Copy link
Contributor

^ OR we need to properly quote model name when constructing that error handling function

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

3 participants