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

Query Builder cannot use multiple from_() #399

Closed
circulon opened this issue Feb 28, 2021 · 3 comments · Fixed by #401
Closed

Query Builder cannot use multiple from_() #399

circulon opened this issue Feb 28, 2021 · 3 comments · Fixed by #401
Labels
bug An existing feature is not working as intended

Comments

@circulon
Copy link
Contributor

Describe the bug
Using multiple table() or from_() only uses the last one defined

To Reproduce

        builder = (
            QueryBuilder()
                .from_('table_a')
                .from_('table_b')
                .select('table_a.col_1 as data_val')
                .where('table_a.col_q', '=', 5)
                .where_column('table_a.table_b_id', 'table_b.id')
        )

Produces

SELECT "table_a"."col_1" AS data_val FROM "table_b" WHERE "table_a"."col_q" = '5' AND "table_a"."table_b_id" = "table_b"."id"

Expected behavior
Expected query is:

SELECT "table_a"."col_1" AS data_val FROM "table_a", "table_b" WHERE "table_a"."col_q" = '5' AND "table_a"."table_b_id" = "table_b"."id"

Desktop (please complete the following information):

  • OS: Mac OSX
  • Version Catalina 10.15.7

What database are you using?

  • Type: Postgres
  • Version 10.7
  • Masonite ORM v1.0.31
@circulon circulon added the bug An existing feature is not working as intended label Feb 28, 2021
@josephmancuso
Copy link
Member

Hmm.. How did i miss this requirement?? It's so obvious lol

@josephmancuso
Copy link
Member

This is fixed in version 1.0.32. I tried supporting the

builder = (
    QueryBuilder()
        .from_('table_a')
        .from_('table_b')
        .select('table_a.col_1 as data_val')
        .where('table_a.col_q', '=', 5)
        .where_column('table_a.table_b_id', 'table_b.id')
)

syntax but that was too big of a change and I guess I sorta missed the boat on that one somehow ...

Anyway, the only way to do that now will be to use the new from_raw (or table_raw depending on whatever sounds more semantically right at the time).

So this would look something like this:

builder = (
    QueryBuilder()
        .from_raw('table_a, table_b')
        .select('table_a.col_1 as data_val')
        .where('table_a.col_q', '=', 5)
        .where_column('table_a.table_b_id', 'table_b.id')
)

As a side note, I see you are using the alias in the select method. So small but one of my favorite things lol. :)

@circulon
Copy link
Contributor Author

@josephmancuso
Thanks for the fix, sorry to hear that its too big as it "reads" nicely in code but yeah the from_raw() will do just fine.

Thanks for investigating and Yes aliased field vaules help immensely when using the query response back into variables/structs of any type for later use. aka super obvious whats going where and why.

Cheers for the continuous improments as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants