leftJoinAndMapOne does not add target property to entity
See original GitHub issueIssue type:
[X] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[X] postgres
[ ] sqlite
[ ] sqljs
[ ] websql
TypeORM version:
[X] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
I have a Source model which can have many Job models
I want to fetch a given source, and together with the most recently created job.
I use this query:
this
.createQueryBuilder('source')
.leftJoinAndMapOne('lastJob', subQuery => {
return subQuery
.select()
.from(Job, 'job')
.orderBy('"createdAt"', 'DESC')
}, 'job', 'job."sourceId" = source.id')
.where('source.id = :id', { id })
.getOne()
The above will return the Source, but without the lastJob property
If I you getRawOne
It returns the source properties together with the job properties, but they’re not scoped under lastJob
Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:10 (4 by maintainers)
Top Results From Across the Web
leftJoinAndMapOne does not add target property to entity #5637
leftJoinAndMapOne does not add target property to entity #5637 ... The above will return the User, but without the lastPurchase property.
Read more >SelectQueryBuilder | typeorm
Contains all properties of the QueryBuilder that needs to be build a final ... Specifies FROM which entity's table select/update/delete will be executed....
Read more >Is it possible to use subquery in leftJoinAndSelect in TypeORM
Using the SubQueryFactory option does not automatically create the on clause as the condition as it cannot know what the underlying query's ...
Read more >TypeORM - Query Builder with Subquery - DEV Community
This is the main part to demonstrate how we should build complex queries with TypeORM. Target SQL converted to TypeScript with TypeORM. SELECT ......
Read more >Select using Query Builder - typeorm - GitBook
There are two types of results you can get using select query builder: entities or raw results. Most of the time, you need...
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
Still an issue in 2021
same problem with code:
any idea?