Skip to content

Add ability to use find() with inner relations #4837

Closed

Description

@jvieirar

Issue type:

[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

find() instead of createQueryBuilder:
Hi guys,

I'm loving this framework a lot. I'm currently using it with NestJS.
I just want to ask if this already exists or if there is something we could have =):

My schema:
Agent has Location. One to One relationship.
In Location I have 'postcode' and I want to be able to filter by location.postcode.

My goal:

const agentsInPostcode = await this.agentRepository.find({
      relations: ['location'],
      where: { status: 'ACTIVE', location: { postcode: '2010' } },
    });

But this generates a query that looks for agent.location_id = 'null'...

I got it working using createQueryBuilder:

const agentsInPostcode2 = await this.agentRepository
      .createQueryBuilder('agent')
      .leftJoinAndSelect('agent.location', 'location')
      .where("agent.status = 'ACTIVE' and location.postcode = :postcode", { postcode: postcode })
      .getMany();
  1. Is this approach the only one? Is it the most efficient one? I would love to have the syntax with find() working.
  2. Please, let me kindly ask for this feature if it doesn't exist.

Thank you!!
Juan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions