Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Sequelize.js. How to join 2 tables (one to one)

I have 2 tables

--- registries
id name
1  dev
--- registries_meta
registryId data
1          {dev: true}

And how to join it? My code:

  public static associate() {
    RegistriesModel.hasOne(RegistriesMetaModel, { foreignKey: 'registryId', sourceKey: 'id' });
    RegistriesModel.belongsTo(RegistriesMetaModel, { foreignKey: 'id' });
    return;
  }

I got an error:

SQLITE_ERROR: no such column: RegistriesMetaModel.id

How to fix thia stupid associations? Expected query:

SELECT * FROM registries LEFT JOIN registries_meta ON registries.id = registries_meta.registryId;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your case Registries model is target model, and it has RegistriesMeta. So when defining association you need to define them like below:

   Registries.hasOne(RegistriesMeta, {
       foreignKey: "registryId"
   });
   RegistriesMeta.belongsTo(Registries, {
       foreignKey: "registryId"
   });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!