Skip to content

Entity.find where relation and nested relation not generating proper SQL #4906

Closed

Description

@reediculous456

Issue type:

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

Database system/driver:

[ ] cordova
[ ] mongodb
[x] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] 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:

I am trying to use columns from an entities relations and the generated query keeps doing WHERE RelatedEntity.id = NULL instead of WHERE RelatedEntity.someCol = value and if I try to nest related entities it does the same thing.

Code

const _object_ids = (from function call);
const urn_id = (from function call);

Markup.find({
      relations: [ `polyline`, `vendor`, `vendor.department`, `vendor.department.subtotal`, `vendor.department.subtotal.worksheet` ],
      where: {
        polyline: {
          object_id: In(_object_ids),
          urn_id,
        },
        vendor: {
          department: {
            subtotal: {
              worksheet: {
                id: In(_worksheet_ids),
              },
            },
          },
        },
      },
    });

Result

SELECT ...(all columns of all entities)...
FROM "markups" "Markup" 
LEFT JOIN "polylines" "Markup__polyline" ON "Markup__polyline"."id"="Markup"."polyline_id" 
LEFT JOIN "vendors" "Markup__vendor" ON "Markup__vendor"."id"="Markup"."vendor_id" 
LEFT JOIN "departments" "Markup__vendor__department" ON "Markup__vendor__department"."id"="Markup__vendor"."department_id" 
LEFT JOIN "subtotals" "Markup__vendor__department__subtotal" ON "Markup__vendor__department__subtotal"."id"="Markup__vendor__department"."subtotal_id" 
LEFT JOIN "worksheets" "Markup__vendor__department__subtotal__worksheet" ON "Markup__vendor__department__subtotal__worksheet"."id"="Markup__vendor__department__subtotal"."worksheet_id"
WHERE "Markup"."polyline_id" = @0 AND "Markup"."vendor_id" = @1 -- PARAMETERS: [null,null]

Expectation

SELECT ...(all columns of all entities)...
FROM ...(tables and joins from above)...
WHERE "Markup__polyline"."object_id" In(@0, @1, ...) AND "Markup__polyline"."urn_id" = @2 AND "Markup__vendor__department__subtotal__worksheet"."id" In(@3, @4, ...) -- PARAMETERS: [...]
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