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

Incorrect behavior with joins and filters #208

Open
defr0std opened this issue Sep 18, 2020 · 0 comments
Open

Incorrect behavior with joins and filters #208

defr0std opened this issue Sep 18, 2020 · 0 comments

Comments

@defr0std
Copy link

defr0std commented Sep 18, 2020

Which version are you using?
The npm package and version of every component involved in the bug report.
@nanosql/core 2.3.7

Describe the bug
If two tables are joined, the filtering on the join result is inconsistent and wrong.

Take two tables:
Table t1
id: string
value1: string

Table t2
id: string
value2: string

Insert some data.

Table t1:

id value1
1 v1
2 v2

Table t2:

id value2
1 v3
2 v4

Perform a join with filtering:

nSQL("t1")
    .query("select", ["t1.id", "t1.value1", "t2.value2"])
    .join({
      type: "inner",
      with: { table: "t2" },
      on: [["t1.id", "=", "t2.id"]]
    })
    // Uncomment the tests below one by one to see the behavior.

    // Test 1. This works correctly, limits the output to 1 row.
    //.where(["value1", "=", "v1"])

    // This doesn't work, returns nothing, why? It's the same as above
    // but with filter on the other table.
    //.where(["value2", "=", "v3"])

    // Doesn't work, returns nothing, although  it's the same as first,
    // just with the table name prefix.
    //.where(["t1.value1", "=", "v1"])

    // Doesn't work, returns nothing.
    //.where(["t2.value2", "=", "v3"])
    .exec()

Expected behavior
The where function on the result of join should correctly filter the data in any of the joined tables. The column names should be prefixed with table alias for disambiguation.

Example
https://codepen.io/defr0zen/pen/wvGEQBZ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant