Search code examples
typeorm

Typeorm - left join and select only relation entity


I have command:

                .leftJoinAndSelect("permission.user", "user")
                .where("permission.stream = :stream", {stream: req.params.id})
                .getMany();

Which gives me this output:

[
  Permission {
    id: 51,
    user: User { nick: 'jmat', password: 'jmat', email: '[email protected]' }
  }
]

I want only output like this:

[
User { nick: 'jmat', password: 'jmat', email: '[email protected]' }
  }
]

I tried to add rows like this to my code between where and getMany, but it doesnt work. Also tried to use joinAndMap, but didnt solve it neither.

.select(['user'])
.select(['permission.user']

Thank you for your help


Solution

  • Try the option with select and getRawMany

    .leftJoinAndSelect("permission.user", "user")
    .where("permission.stream = :stream", {stream: req.params.id})
    .select("user")
    .getRawMany();