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

216
Views
knex :Multilevel join through relationMappings nodejs

I have three tables.

Table name : question, question_option,answer

answer table cotains question_option_id, question_option table contains question_id;

Now I have answer_id by which I want question data. but I am getting error like

 "Error: A model class Answer doesn't have relation question",

My mappings are for QuestionOption

static get relationMappings() {
return {
  question: {
    relation: Model.HasOneRelation,
    modelClass: Question,
    join: {
      from: 'question_option.question_id',
      to: 'question.id',
    }
  }
};

}

for answer

 static get relationMappings() {
    return {
      question_option: {
        relation: Model.HasOneRelation,
        modelClass: QuestionOption,
        join: {
          from: 'answer.question_option_id',
          to: 'question_option.id',
        }
      }
    };
  }

what I need here in sql

SELECT a.name, qo.name, q.name FROM public.answer a inner join question_option qo on qo.id = a.question_option_id
inner join question q on q.id = qo.question_id
WHERE .....

knex query

await Answer.query().select('answer.name as answer', 'question_option.name as questionOption').joinRelated(QuestionOption).joinRelated(Question).joinRelated("[question]").where({ "answer.user_id": id});

thanks

about 4 years ago · Juan Pablo Isaza
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!