CRUD: [Bug] Field relationship_select causes QueryException when validation fails.

Bug report

Refs; Probably related to this PR: https://github.com/Laravel-Backpack/CRUD/pull/4002

What I did

Created/Updated resource that contains values inside relationship_select field and validated request. Validation rules doesn’t have anything to do with relationship_select CRUD field.

Field Definition

        CRUD::addField([
            'name'    => 'origins',
            'label'   => 'Assosciate Origins.',
            'tab'   => 'Relationships',
            'wrapper' => [
                'class' => 'form-group col-md-6',
            ],

            'pivot_selector' => [
                'wrapper' => [
                    'class' => 'form-group col-md-6',
                ]
            ],
            'pivotFields' => [
                [
                    'name'    => 'as',
                    'type'    => 'text',
                    'wrapper' => [
                        'class' => 'form-group col-md-6',
                    ],
                ],

            ],

What I expected to happen

If validation passes:

  • Create/Update Resource

If validation fails:

  • Redirect back with validation errors being displayed.

What happened

Illuminate\Database\QueryException
SQLSTATE[HY093]: Invalid parameter number (SQL: select * from `origins` where `id` in (2)) (View: /xxx/xxx/xxx/vendor/backpack/crud/src/resources/views/crud/fields/relationship/relationship_select.blade.php)

This only occurs when validation fails and relationship_select field has any data.

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.13 (cli) (built: Nov 22 2021 09:50:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies

### LARAVEL VERSION:
v8.77.0@148b0df9eaac9f89bebb6b6fbbb0e9874e62ecc7

### BACKPACK VERSION:
4.2.x-dev@69d7047ae60a2c45a0cd02c9e56553f42e961d72

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

@tabacitu I think this is fixed for long time now.

I am going to close and re-open if someone pings here.

Cheers

This is fixed I think.

Please re-open or comment if I am wrong.

Thanks for testing 4.2 @PitchRE , since this issue was opened alot of stuff have been added/fixed regarding relationships specially in the last days with nested relations.

Let us know if you find something broken while using that branch 😃

Pedro