Skip to content

Subqueries break upgrading from 1.4.0 to 1.5.3 #1205

@nazar

Description

@nazar

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

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