Skip to content

leftJoinAndMapOne does not add target property to entity #1882

@madshargreave

Description

@madshargreave

Issue 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions