sequelize does not support JSONB column as foreign key
See original GitHub issueI 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:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Feels really dirty to me to use a json column as a primary key - Whats wrong with a regular
SERIAL
😃?It is just a test to use a JSONB column as primary key.