-
Notifications
You must be signed in to change notification settings - Fork 917
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] Unable to save empty input with relation HasOne #3944
Comments
Hello there! Thanks for opening your first issue on this repo! Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that. Backpack communication channels:
Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch. Thank you! -- |
Hey @tabacitu I was totally aware of this. And I already tried to fix it, but it would be a major BC. Problem is here:
The check for This is connected with the saving process for multiple entries somehow, because I broke it when trying to fix this and we needed to revert the PR. In relationship branch I removed this The solution I've found goes along this lines: private function getRelationDataFromFormData($data)
{
$relation_fields = $this->getRelationFields();
$relation_fields = $this->parseRelationFieldNamesFromHtml($relation_fields);
//remove fields that are not in the submitted form.
$relation_fields = array_filter($relation_fields, function ($item) use ($data) {
return Arr::has($data, $item['name']);
});
$relationData = [];
foreach ($relation_fields as $relation_field) {
$attributeKey = $relation_field['name'];
if (isset($relation_field['pivot']) && $relation_field['pivot'] !== true) { Let me know what you think. I think we cannot fix it without BC because we cannot run the inverse of Removing the Pedro |
Aahh 😡 It's that damn Ok so... here's a wild idea @pxpm ... what if we... skip that middleware when we want to 👀 ? Previously that was impossible (or at least very difficult), but starting with Laravel 8.36 (april 2021), the middleware has a This is either a brilliant idea, or a very stupid one. Can't figure out which one it is at the moment... 😅 |
@CinexUA another idea that I workaround for this issue.
Inspired by Apply it like
Hope it helps :-) @tabacitu @pxpm |
Heads-up - this has been fixed in #4066 Starting with Backpack 4.2, you can use HasOne and MorphOne relationships in two ways: // add text/number/etc fields for each related attribute
CRUD::field('userInfo.first_name');
CRUD::field('userInfo.last_name');
// add one field for all attributes (it will load a repeatable field with one item behind the scenes)
CRUD::field('userInfo')->subfields([
['name' => 'first_name', 'type' => 'text'],
['name' => 'last_name', 'type' => 'text'],
]); The first method will NOT allow the admin to ever delete the related entry. Just update it. 🎉 So I'll be closing this. If after the 4.2 upgrade you're still having this issue, please reply here again, we'll re-open and re-investigate. |
Hi! When will laravel backpack 4.2 update be released? I don't want to upgrade to version 5.0 just to avoid this bug. |
Hi @CinexUA , In short, Backpack v4.2 == Backpack 5.0. But it should be a free upgrade for you, if you purchased Backpack after Feb 9th 2021. You can read more about that here. And the upgrade process itself shouldn't be a long one at all. Cheers! |
Bug report
What I did
Sometimes it is necessary to delete data from input with relation
HasOne
I try to store at least one input blank from the list:
What I expected to happen
I expected to see an empty field when I delete data from it
What happened
Data in input can only be written, changed but not deleted. I want to be able to delete data from the input field.
What I've already tried to fix it
I was looking for a solution on the Internet, in the official documentation, stackowerflow and other resources, but could not find anything
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:
PHP 8.0.10 (cli) (built: Sep 3 2021 17:04:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
LARAVEL VERSION:
v8.70.2@dec9524cd0f9fa35a6eb8e25d0b40f8bbc8ec225
BACKPACK VERSION:
4.1.60@bec5cfa11f0cd0712c79256748acf5850080c0ee
The text was updated successfully, but these errors were encountered: