-
Notifications
You must be signed in to change notification settings - Fork 906
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
[Bug] Delete the last item in relationship
(with subfileds) with DB col constrained
#5742
Comments
Based on the information provided in the knowledge sources, this issue appears to be a known bug in Backpack CRUD that has been reported and addressed in previous versions. The problem you're experiencing is related to how Backpack handles the deletion of the last item in a HasMany relationship field with subfields. This issue is similar to the one described in Github Issue #4187, where deleting the last entry in a HasMany relationship tries to update the entry with a null foreign key instead of deleting it. The solution to this problem was implemented in Pull Request #4205, which addressed the issue of deleting the last entry in HasMany relationships. However, since you're using the latest version of Backpack (6.7.45) and still experiencing this issue, it seems that the problem may have resurfaced or wasn't completely resolved for all scenarios. To work around this issue, you can try the following:
[
'name' => 'medias',
'label' => 'Product Images & Videos',
'type' => 'relationship',
'force_delete' => true,
// ... other attributes
] This should force Backpack to delete the related entries instead of trying to update them with a null foreign key.
I recommend reporting this issue to the Backpack GitHub repository, as it seems to be a regression of a previously fixed bug. Provide them with the details you've shared here, including your Backpack version and the specific field configuration you're using. Github Issues for Backpack CRUD is the best place to report this bug and get assistance from the Backpack maintainers. ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Github Issue (closed): [Bug] Deleting last relation tries to update this record and throws an error |
Bug report
A simple
relationship
field with subfield[MUST] with SQL Constraints
What I did
What I expected to happen
the LAST item removed without SQL error, just like delete the other items.
What happened
it tried to set
product_id
= 0 which trigger Integrity constraint violation.What I've already tried to fix it
remove the SQL Constraints
This works perfectly.
Is it a bug in the latest version of Backpack?
After I run
composer update backpack/crud
the bug... is it still there?Yes
Backpack, Laravel, PHP, DB version
When I run
php artisan backpack:version
the output is:PHP VERSION:
8.3.12
PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, bcmath, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, imagick, imap, intl, ldap, exif, msgpack, mysqli, pcov, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, readline, shmop, SimpleXML, soap, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, memcached, redis, swoole, Zend OPcache, xdebug
LARAVEL VERSION:
11.36.1.0
BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.3.6
backpack/crud: 6.7.45
backpack/filemanager: 3.0.10
backpack/generators: v4.0.7
backpack/medialibrary-uploaders: 1.2.1
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.29
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.17
Additional Information
Just a normal Product has Many ProduceMedia
The text was updated successfully, but these errors were encountered: