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

Ambigous foreign key column reference #8289

Closed
3 tasks done
mhdaouas opened this issue Sep 24, 2021 · 3 comments · Fixed by #8334
Closed
3 tasks done

Ambigous foreign key column reference #8289

mhdaouas opened this issue Sep 24, 2021 · 3 comments · Fixed by #8334
Assignees
Labels

Comments

@mhdaouas
Copy link

mhdaouas commented Sep 24, 2021

Preflight Checklist

Describe the Bug

I created different relation type fields (like O2M) in a single content type object and named the foreign key as "role" (I wanted to refer to the directus_roles table to have a list of roles in the object to be able to configure a workflow). Now I'm unable to access the app (white screen) and I get this error "column reference "role" is ambiguous".

I also deleted the single content type table and recreated it but couldn't get back the app to work.

To Reproduce

See above

What version of Directus are you using?

9.0.0-rc.93

What version of Node.js are you using?

14.16.1

What database are you using?

Postgresql 13

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying Directus?

Locally on Visual Code

@mhdaouas
Copy link
Author

Ok I figured out that a role column with integer type has been added to directus_roles so I deleted it and fixed the problem.

@mhdaouas mhdaouas reopened this Sep 24, 2021
@mhdaouas
Copy link
Author

I re-opened the issue because I believe this case should be taken into consideration by preventing the user from using a standard column name like "role" in this case.

@azrikahar
Copy link
Contributor

Ok I figured out that a role column with integer type has been added to directus_roles so I deleted it and fixed the problem.

Thanks for the investigation! That helps alot to narrow down what happened.

Upon investigation, seems like it's not really standard column name being the issue (as directus_user always have been using role as the column name), but more so the API middleware here:

const user = await database
.select('role', 'directus_roles.admin_access', 'directus_roles.app_access')
.from('directus_users')
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')

Notice how line 42 just selects role, but there's 2 possibilities (after your above action) now which are directus_users.role and directus_roles.role, hence the "ambiguous" error. Ensuring we select directus_users.role (same like line 44) will prevent such error from ever happening 👍 Just tested and that fix worked. Thanks again for re-opening the issue for us to properly look into it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants