-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: [DBForge] addForeignKey() Table prefix issue while using with database #9085
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
Conversation
While adding a foreign key to any external table, it was getting miss formatted if we defined the DB prefix like db2.table_name is being formatted like prefix_db2.tablename and the query was ended up in malformed constraint error. This fix will add prefix to the table name only.
Thank you for sending this PR! We expect the following in all Pull Requests (PRs).
Important We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works. If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work on the framework than you do. Please make it as painless for your contributions to be included as possible. See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md |
Why do you need to specify the table name like So I think it is just a misuse, not a bug. |
People often use external table foreign relationships. Just like in my case where i wanted to add foreign key with tablea from databasea to tableb of databaseb, and was getting it formatted like " |
Okay, that makes sense. In any case, please fix all errors in GitHub Actions. |
We have a command to fix coding style.
See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#php-style |
I am not working with composer until SDLC. Right now i am at pre planning phase and only able to structure my code. |
Sorry, I don't get what you mean by "until SDLC". If you don't use Composer, you cannot run PHPUnit. In any case, we do not accept PRs without test code. |
Actually i ran the fixer couple of times (on standalone installation) and only change the specific 3 lines. |
While inserting and updating the data table prefix was getting doubled if use with database name like if we define the table name as "database.tablename" it working fine for selects but for updates and inserts it converting the table name such as "`database`.`pfix_``pfix_tablename". So this minor fix will not append the prefix to the table name if it is already existed in table.
Merge with latest updates
Ran cs-fix as per PSR-12 standards and updating the snippet only
Please make sure to update the packages first with the following command. composer update Then run command : git switch patch-1 Then run composer cs-fix git add system/Database/Forge.php system/Database/BaseConnection.php
git commit -m "style: fix code style"
git push origin patch-1 |
By the way, can you write test code? We do not accept PRs without test code. |
Important We expect all code changes or bug-fixes to be accompanied by one or more tests This PR does not have the necessary test code. If you want this PR to be reviewed, please add the test code. If the test is not added, this PR will be closed. |
While adding a foreign key to any external table, it was getting miss formatted if we defined the DB prefix like
db2.table_name
is being formatted likeprefix_db2.tablename
and the query was ended up in malformed constraint error.This fix will add prefix to the table name only.
Description
I have changed the logic of adding prefix for foreign tables and now prefix will only prepend with table name only (last index)
Checklist: