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

Search by field with different table name #196

Open
jaulz opened this issue Nov 5, 2024 · 2 comments
Open

Search by field with different table name #196

jaulz opened this issue Nov 5, 2024 · 2 comments
Labels
pkg: graphql scope: feat New feature or request

Comments

@jaulz
Copy link

jaulz commented Nov 5, 2024

Right now, the name of the table of is prepended to any filter defined by @searchBy, e.g. users.active. However, with custom queries I have a case where I would like to query a field on a different table of the query. I think the easiest would be to use the rename directive (e.g. @rename( attribute: "related_table.name" )) and within the query enhancer check if the attribute contains a dot?

@LastDragon-ru LastDragon-ru added pkg: graphql scope: feat New feature or request labels Nov 5, 2024
@LastDragon-ru
Copy link
Owner

Right now, the name of the table of is prepended to any filter defined by @searchby, e.g. users.active.

Yep (but only for Eloquent), it is required to avoid "Integrity constraint violation: 1052 Column 'xxx' in where clause is ambiguous" error when query has joins.

I think the easiest would be to use the rename directive (e.g. @rename( attribute: "related_table.name" )) and within the query enhancer check if the attribute contains a dot?

To be honest, I'm not sure. I always prefer explicit form ({ relation { name }}) and never used @rename :) Maybe overriding/implementation of the BuilderFieldResolver will be easy?

@jaulz
Copy link
Author

jaulz commented Nov 12, 2024

Okay, thanks for the hint. I will have a look 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: graphql scope: feat New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants