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

Using a batched junction with non-id column causes the column to not be added to the shape #270

Open
bradzacher opened this issue Dec 7, 2017 · 2 comments

Comments

@bradzacher
Copy link
Contributor

creating a batched junction as follows:

field:  {
    junction: {
        uniqueKey: ['id', 'id'],
        sqlTable: 'junction',
        sqlBatch: {
            parentKey: 'junc_col',
            thisKey: 'junc_col',
            sqlJoin: (a, b) => `${a}.fielda = ${b}.fieldb`,
        },
    },
}

causes the base SQL to be generated correctly:

SELECT id as `id`,
    junc_col as `junc_col`,
FROM base

However it fails to add the junc_col to the shape definition.
This means that when it generates the batch SQL, it has no column data, so it attempts to find WHERE junc_col IN (NULL).

I'm not knowledgable enough with the codebase to be sure, but the problem is either:

  • it's not adding it to the SQL AST, which means that the shape definition function doesn't know to pick it up.
    • this would make sense if it wasn't dumped into the base table SQL.
  • there is an issue with the _defineShape function; it doesn't look into batched tables to determine if if it needs extra columns.

I'm leaning toward the latter as the bug - it seems to be a mismatch between the logic in the SQL stringifier and the shape definer.

@bradzacher
Copy link
Contributor Author

note that a workaround for now is to add the required column to the alwaysFetch property.
This will cause JM to always add it correctly to the shape.

@nicoabie
Copy link
Contributor

nicoabie commented May 5, 2024

Can you come up with an example using https://github.com/join-monster/join-monster-sscce ?

Is uniqueKey: ['id', 'id'], correct?

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

No branches or pull requests

2 participants