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

Scoped queries with association comparison in filter breaks transformation #935

Open
patricebender opened this issue Dec 5, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@patricebender
Copy link
Member

patricebender commented Dec 5, 2024

Given this model:

entity Bar {
  key ID   : Integer;
      baz  : Association to Baz;
      hurz : Association to Hurz;
}

entity Baz {
  key ID : Integer;
}

entity Hurz {
  key ID : Integer;
}

the where clause of the exists subquery is broken:

> q = SELECT.from('Bar[baz = 1 and baz = ID]:hurz')
Query {
  SELECT: {
    from: {
      ref: [
        {
          id: 'Bar',
          where: [
            { ref: [ 'baz' ] },
            '=',
            { val: 1 },
            'and',
            { ref: [ 'baz' ] },
            '=',
            { ref: [ 'ID' ] }
          ]
        },
        'hurz'
      ]
    }
  }
}
> q.forSQL()
Query {
  SELECT: {
    from: { ref: [ 'Hurz' ], as: 'hurz' },
    where: [
      'exists',
      {
        SELECT: {
          from: { ref: [ 'Bar' ], as: 'Bar' },
          columns: [ { val: 1 } ],
          where: [
            { ref: [ 'Bar', 'hurz_ID' ] },
            '=',
            { ref: [ 'hurz', 'ID' ] },
            'and',
            { xpr: [ { ref: [ 'Bar', 'baz_ID' ] }, '=', { val: 1 } ] },
            'and', // ❌❌❌❌
            '=',
            { ref: [ 'Bar', 'ID' ] }
          ]
        }
      }
    ],
    columns: [ { ref: [ 'hurz', 'ID' ] } ]
  }
}

also broken in a different way if the condition is flipped:

> q = SELECT.from('Bar[baz = 1 and ID = baz]:hurz')
Query {
  SELECT: {
    from: {
      ref: [
        {
          id: 'Bar',
          where: [
            { ref: [ 'baz' ] },
            '=',
            { val: 1 },
            'and',
            { ref: [ 'ID' ] },
            '=',
            { ref: [ 'baz' ] }
          ]
        },
        'hurz'
      ]
    }
  }
}
> q.forSQL()
Query {
  SELECT: {
    from: { ref: [ 'Hurz' ], as: 'hurz' },
    where: [
      'exists',
      {
        SELECT: {
          from: { ref: [ 'Bar' ], as: 'Bar' },
          columns: [ { val: 1 } ],
          where: [
            { ref: [ 'Bar', 'hurz_ID' ] },
            '=',
            { ref: [ 'hurz', 'ID' ] },
            'and',
            { xpr: [ { ref: [ 'Bar', 'baz_ID' ] }, '=', { val: 1 } ] },
            'and',
            { ref: [ 'Bar', 'ID' ] },
            '=',
            { ref: [ 'Bar', 'baz' ] } // ❌❌❌❌
          ]
        }
      }
    ],
    columns: [ { ref: [ 'hurz', 'ID' ] } ]
  }
}
@patricebender patricebender added the bug Something isn't working label Dec 5, 2024
@patricebender patricebender self-assigned this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant