Empty name for subfields not handling properly
See original GitHub issueBug report
What I did
I was using a select2 to populate the read-only fields in the form in v4.1
To quickly trick the CRUD ignore this nested field, i set the field to be empty name
.
In v5, it is not properly handled…
'name' => 'jobs',
'label' => 'Jobs',
'type' => 'relationship',
'subfields' => [
[
'name' => '',
'label' => "Dummy Select",
'type' => 'select2_from_array',
'options' => $this->options,
'allows_multiple' => false,
'wrapper' => ['class' => 'form-group col-md-3 dummy-select2'],
],
What I expected to happen
Understand that it is documented as name
is a mandatory attribute.
However, an empty string is not considered as undefined name.
I need the proper way to skip this field. https://backpackforlaravel.com/docs/5.x/upgrade-guide#step-15
Maybe a meaningful Exception should be thrown to tell name
cannot be empty string?
What happened
With Empty Name
With Name
So, it breaks when trying to save
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'jobs[-1' in 'field list'
What I’ve already tried to fix it
N/A
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.16 (cli) (built: Feb 21 2022 14:42:00) ( NTS ) Copyright © The PHP Group Zend Engine v4.0.16, Copyright © Zend Technologies with Zend OPcache v8.0.16, Copyright ©, by Zend Technologies
LARAVEL VERSION:
v8.83.2@b91b3b5b39fbbdc763746f5714e08d50a4dd7857
BACKPACK VERSION:
5.0.9@d995de2026b6fcb1b13b469f371c929c29d1c1cc
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
I’ve sent #4268 to address this.
Thanks again @kiddtang !
Best, Pedro
I TOTALLY agree with that. Just talked to Pedro about this yesterday… that we should throw an error with a clear message. If an empty name in a field triggers an error… then an empty name in a subfield should trigger an error too.
Please open issues when you find other confusing errors like this. It’s something we want from Backpack v5, to be a lot easier to debug. The more clear errors messages we throw, the faster developers can know what to do, instead of searching or scratching their heads.