Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
reediculous456 opened this issue Oct 14, 2019 · 1 comment · Fixed by #7805
Closed

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

reediculous456 opened this issue Oct 14, 2019 · 1 comment · Fixed by #7805

Comments

@reediculous456
Copy link

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
Projects
None yet
3 participants