Skip to content

aliasFor not working when used with query() #1957

@patrikwalker

Description

@patrikwalker

Hi,

I stumbled upon an issue with aliasFor, it doesn't seem to work when used with a query directly, like described in the docs. But everything seems to work fine if used with $relatedQuery.

I used the reproduction template to test it (I added an extra property named someProp):

const jennifer = await Person.query().findOne({ firstName: 'Jennifer' });

// this works fine
const jenniferMovies = await jennifer
  .$relatedQuery('movies')
  .aliasFor('Person_Movie', 'pm')
  .where('pm.someProp', 100);

// this doesn't alias Person_Movie correctly and throws an error because pm is not known
const jenniferWithMovies = await Person.query()
  .findOne({ firstName: 'Jennifer' })
  .aliasFor('Person_Movie', 'pm')
  .joinRelated('movies')
  .where('pm.someProp', 100);

This also explains why the test pass: They only test for the case with the $relatedQuery.

This should be working, or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions