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
fix(database): add prefix to avoid join column name conflicts #20027
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…i/strapi into fix/conflicting-join-alias
@pwizla This is targeting v4, and could technically be considered a breaking change although it is very unlikely to affect anyone, but we should probably document somewhere that you can't use |
Quality Gate passedIssues Measures |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QAed this and works as expected!!
What does it do?
Uses an alias for the join column name to prevent it conflicting with a column name on the main table.
Why is it needed?
If the join column name was the same as a column name in the main content type's table, it was always overwritten.
So for example, in #18085 , if we create a
shirt
content type with ashirt_id
attribute, and then have a relation to it, the join was usingshirt_id
as the join column name, overwriting theshirt_id
attribute ofshirt
.Technically this is still the case, but it's extremely unlikely someone would have an attribute in a content type named
__strapi{ct name}_id
unless they were intentionally trying to encounter this issue. Regardless, In Strapi 5 it will be an officially reserved prefix.This should be safe for long identifiers in the db, because any existing database with a join table will include an index named
{ct name}_{attribute name}_unique
Which means, given a minimum 1 char for ct name, we have len(
1__unique
) = 9 > len(__strapi
) and should not hit any limit that isn't already being hit.How to test it?
see #18085
Related issue(s)/PR(s)
Fixes #18085
DX-1178