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

[Bug] hasMany fields should delete repeatable entries by default #4187

Closed
olipayne opened this issue Feb 12, 2022 · 2 comments
Closed

[Bug] hasMany fields should delete repeatable entries by default #4187

olipayne opened this issue Feb 12, 2022 · 2 comments
Assignees
Labels

Comments

@olipayne
Copy link
Contributor

olipayne commented Feb 12, 2022

Bug report

When using a repeatable field on a hasMany relationship, if there is one record and the repeatable field doesn't have a 'force_delete' => true attribute, if you try to delete that sole entry then it tries to update the single entry with a foreign_key_id of null, instead of deleting it.

What I did

Adding a 'force_delete' => true to the relationship field makes it delete, if not then it passes down to

return $removedEntries->update([$relationForeignKey => null]);
and it doesn't like a null entry on a foreign key.

What I expected to happen

When removing the sole entry in the relationship, it should delete the entry in the related model table

What happened

It tried to set the user_id value to null.

What I've already tried to fix it

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
PHP 8.0.15 (cli) (built: Jan 21 2022 04:49:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.15, Copyright (c), by Zend Technologies

### LARAVEL VERSION:
v9.0.2@4c7cd8c4e95d161c0c6ada6efa0a5af4d0d487c9

### BACKPACK VERSION:
5.0.6@2be4ff8407259f528a3541f0569ce156bab63165
@olipayne
Copy link
Contributor Author

Just checked, my foreign key column is not nullable ;)

@pxpm
Copy link
Contributor

pxpm commented Feb 16, 2022

Hey @olipayne once again thanks 🙏 I will spend all my thanks with you I see! 😄

I've just submitted #4205 that should address this issue so I am going to close here.

If you happen to test the PR let us know if it's fixed for you (it should, I added tests for it 😅 )

Wish you the best,
Pedro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants