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

Subqueries break upgrading from 1.4.0 to 1.5.3 #1205

Closed
nazar opened this issue Jan 25, 2019 · 3 comments · Fixed by ovos/objection.js#13 or #2405
Closed

Subqueries break upgrading from 1.4.0 to 1.5.3 #1205

nazar opened this issue Jan 25, 2019 · 3 comments · Fixed by ovos/objection.js#13 or #2405

Comments

@nazar
Copy link

nazar commented Jan 25, 2019

Greetings,

Subqueries using .with are no longer working as expected when I upgrade from 1.4.0 to 1.5.3.

  return Model
    .query()
    .with(
      'pager_subquery',
      query
    )
    .count()
    .from('pager_subquery')
    .first();

The above code takes a query, which is an objection model .query() and uses it to construct a subquery using .with to return a basic row count.

Under 1.4.0, the following correct SQL is generated:

with "pager_subquery" as (select "posts".* from "posts" where "posts"."postable_id" in ($1) and "postable_type" = $2 and "posts"."deleted_at" is null order by "stats"#>'{scores,low}' desc) select count(*) from "pager_subquery"

Under 1.5.3, the following incorrect SQL is generated:

with "pager_subquery" as (select "pager_subquery".* from "pager_subquery" where "pager_subquery"."postable_id" in ($1) and "postable_type" = $2 and "posts"."deleted_at" is null order by "stats"#>'{scores,low}' desc) select count(*) from "pager_subquery"

It appears that under 1.5.3, the original query object loses its model tablename and/or is overridden by the .from('pager_subquery') method call.

I had a look through the change log and couldn't find anything that indicates that this behaviour has changed.

Is this a bug or has Objection changed this behaviour? If the latter, any hints or clues would appreciated.

Libraries:

  • knex: 0.16.3
  • pg: 7.8.0
  • db: Postgres 10.5
@koskimas
Copy link
Collaborator

koskimas commented Jan 26, 2019

This is probably a bug in objection. I'm on vacation for three weeks. I'll look into this after I'm back

@nazar
Copy link
Author

nazar commented Feb 14, 2019

Thank you for this @koskimas! And super thanks for objection.js - words cannot describe how much I ❤️it and how pleasurable it is to use.

@koskimas
Copy link
Collaborator

objection 1.6 is now released with a fix for this issue.

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