Skip to content

Inner joining to left joined table returns 0 rows #3080

Closed

Description

@harm-less

Issue type:

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

Database system/driver:

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

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.4

Steps to reproduce or a small repository showing the problem:

Hey,
We ran into a problem with joining some relations and getting 0 results. The problem (and the solution) is described best in this StackOverflow.

I, therefore, don't know if this should be considered a bug or a feature request, because the order of the ON keywords and joins seems to matter in this instance as can be seen from the accepted answer in the StackOverflow question.

I guess a solution could be to move the ON logic to underneath all the LEFT and INNER joins and reverse the order. Or would this be too simple if there's a whole bunch of joins instead of just 2?

For the time being, we're planning on making sure the child relations are always LEFT JOIN instead of 'INNER JOIN' so at least we're getting our results. This will give artefacts, but the amount of instances in our codebase like this at the moment is not that high.

Thanks in advance!

Activity

  1. jonaaix commented on Nov 9, 2018

    @jonaaix

    Did you already test/debug the output SQL and running it without typeorm? It would be helpful if you provide a code snippet.
    You can specify explicitly which columns should be joined, by using the third parameter. One time I had the issue that the relation was not resolved properly and invalid SQL was generated. This was the workaround.

    .getRepository('user')
    ...
    // table, alias, condition
    .innerJoinAndSelect('gender', 'gender', 'user.ofGender = gender.genderId')
  2. Kononnable commented on Dec 8, 2018

    @Kononnable
    Contributor

    @harm-less
    Without code snippet, generated query and query you want to generate we wont't be able to help.

  3. pleerock commented on Jan 7, 2019

    @pleerock
    Member

    @harm-less did you find a solution for your issue?

  4. harm-less commented on Jan 7, 2019

    @harm-less
    ContributorAuthor

    I didn't yet, I'm still trying to find time to properly reply to this topic but other priorities keep coming up at work atm.

  5. pleerock commented on Jan 7, 2019

    @pleerock
    Member

    let me close this issue then, create a new one with additional information once you'll have a time

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

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