question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sequelize does not support JSONB column as foreign key

See original GitHub issue

I tried to make a JSONB column as a primary key. It’s OK for postgreSQL and normal use of sequelize. But it will get error when use the getXXX associate function.

in model.js

    if (typeof param === 'number' || typeof param === 'string'  || Buffer.isBuffer(param)) {
      options.where = {};
      options.where[this.primaryKeyAttribute] = param;
    } else {
      throw new Error('Argument passed to findById is invalid: '+param);
    }

The if statement should be

    if (typeof param === 'number' || typeof param === 'string'  || typeof param === 'object' || Buffer.isBuffer(param)) {

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
janmeiercommented, Aug 9, 2016

Feels really dirty to me to use a json column as a primary key - Whats wrong with a regular SERIAL 😃?

0reactions
frogcjncommented, Aug 9, 2016

It is just a test to use a JSONB column as primary key.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use json attribute as Foreign Key and format it to uuid
The foreignkey is the column name in the second table. Did you make sure that the author column exists inside of the user...
Read more >
Model Querying - Finders - Sequelize
It generates a standard SELECT query which will retrieve all entries from the table (unless restricted by something like a where clause, for ......
Read more >
Using Basic and Advanced Sequelize Features - Section.io
Sequelize only supports relational databases. Databases like Mongo DB or other NoSQL databases are not supported. Sequelize supports solid ...
Read more >
Indexes and check constraints on json and jsonb columns
Here is an example. To reduce clutter, the primary key is not defined to be self-populating. create table ...
Read more >
Associations - Manual | Sequelize
Sequelize allow setting underscored option for Model. ... The target key is the column on the target model that the foreign key column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found