Skip to content

Conversation

@lehni
Copy link
Collaborator

@lehni lehni commented Apr 15, 2023

Closes #2251

@lehni lehni merged commit 9b92eb1 into master Apr 15, 2023
@comp615
Copy link
Contributor

comp615 commented Jul 14, 2023

@lehni This commit seems to have caused a regression for us in 3.0.3 and maybe should potentially be reverted (or maybe our whole pattern is wrong).

We use a custom query builder to always eager load an association:

// The custom query builder always eager loads the assigned user roles, which
// ensures that we're always able to access the userRole virtual attribute
class UserQueryBuilder<M extends Model, R = M[]> extends QueryBuilder<M, R> {
  execute() {
    void this.withGraphFetched('assignedUserRoles');
    return super.execute();
  }
}

However in a few places and tests, we do something like:

await User.query(txn)
        .where({ id: myUser.id })
        .patch({ status: 'disabled' });

But in 3.0.3 this started throwing:

 DataError: select "assigned_user_role".* from "assigned_user_role" where "assigned_user_role"."userId" in ($1) - invalid input syntax for type uuid: "1"

The userId is obviously defined as a uuid. I was able to get around this and fix our build by changing the execute override to the following. But I'm not confident that this won't break other usages like a patch and select and is correct.

class UserQueryBuilder<M extends Model, R = M[]> extends QueryBuilder<M, R> {
  execute() {
    if (!this.isUpdate()) {
      void this.withGraphFetched('assignedUserRoles');
    }
    return super.execute();
  }
}

Was curious if you could lend some sage advice on the issue. Thanks!

@lehni
Copy link
Collaborator Author

lehni commented Jul 16, 2023

@comp615 oh that doesn't sound good! Are you certain that the regression is caused by this commit? Could you open a new issue for this problem, and provide a reproduction for it, perhaps using the reproduction-template.js file if possible? That would be very useful to debug the source of your issue. I don't fully grasp how the two things are related from your description. Thanks!

@lehni
Copy link
Collaborator Author

lehni commented Jul 20, 2023

@comp615 I figured it out now, fix coming up: #2476

@lehni
Copy link
Collaborator Author

lehni commented Jul 20, 2023

Released in v3.0.5

@lehni lehni deleted the fix/remove-instanceof-in-graph-fetched branch July 21, 2023 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overwritten fromDatabaseJson does not fetch relations

3 participants