How can I left-join query with TypeOrm
See original GitHub issueIssue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem: There are some tables:
CREATE TABLE a (
a_id serial PRIMARY KEY,
name text
);
CREATE TABLE b (
a_id integer REFERENCES a (a_id),
name text
);
CREATE TABLE c (
a_id integer REFERENCES a (a_id),
name text
);
And then I want to query something like this:
SELECT * FROM a
LEFT JOIN b USING (a_id)
LEFT JOIN c USING (a_id)
;
How do I query above with TypeOrm?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top Results From Across the Web
TypeORM basic join explanation - Stack Overflow
The leftJoinAndSelect("user.photos", "photo") references the property photos defined in the User entity. It's the last line in the User class.
Read more >typeorm.SelectQueryBuilder.leftJoin JavaScript and ... - Tabnine
How to use. leftJoin. function. in. SelectQueryBuilder. Best JavaScript code snippets using typeorm.SelectQueryBuilder.
Read more >TypeORM - Query Builder - Tutorialspoint
TypeORM - Query Builder, Query builder is used build complex SQL queries in an easy way. ... Let us perform simple left join...
Read more >Joins and Queries with Different ORM Tools
SQL Joins using ORM and Query Builders SQL JOIN simple definition from (w3schoo.com) A... Tagged with javascript, node, typeorm, ...
Read more >TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
Select using Query Builder · Insert using Query Builder · Update using Query Builder · Delete using Query Builder · Working with Relations...
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
Try adding this decorator to your a-model
I think the error is because it cannot find the relation (Only defined from b-side not from the a-side)
Then you should be able to do the following:
Thats how I do it.
@Flusinerd Thank you for your fast replying. I just tried QueryBuilder with something like this:
When I used
.getOne()
, I couldn’t get the value ofb.name
in return value. When I used.getRawOne()
, I could get the value in return value, but type of return value was just object, notADbModel
(entity of a).So could I get the value of
b.name
withADbModel
(entity type)?