0

Can anyone please give a TypeORM solution for the below query,

select upr.active, pr.preference from user_preferences upr
left join preferences pr
on upr.preferenceid = pr.id
where upr.userid = 1

The output is,

active  preference
TRUE    update
TRUE    insert

My TypeORM repo names are preferenceRepo, userPreferenceRepo

Thanks.

1
  • 1
    What have you tried yourself? Commented Jan 11, 2021 at 7:29

1 Answer 1

2

you simply need to do:

return  this.userPreferenceRepo.createQueryBuilder('upr') 
    .leftJoin("upr.preferenceid", "pr") // replace preferenceid with the name of the colmun that relate user and Preference entity 
   .select(["upr.active","pr.preference"])
   .where("upr.userid = :id ", { id: id }) 
   .getRawMany();
Sign up to request clarification or add additional context in comments.

1 Comment

Nice. Yes its working fine. Thank u so much ! - @Youba

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.