CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

[Bug] relationship field and morphTo - 2nd select is not showing labels

Open realtebo opened this issue 10 months ago • 2 comments

Bug report

What I did

I have a table 'movements' with fields coinable_id and coinable_type

I have a activities table with an id and a name column (and some populated records )

In the Movement model class I added the following morphTo

public function coinable(): MorphTo
    {
        return $this->morphTo();
    }

In the MovementCrudController, in the setupCreateOperation I added the relationship field

    CRUD::field([
        'type' => 'relationship',
        'name' => 'coinable',
    ])
        ->addMorphOption(Activity::class, 'Attività');
    ;

What I expected to happen

I expected to see a select for the type Then choosing the activity type, I expected to see in the 2nd select all the records from activities table. To be precise, I expected to see 'names' showed as label

I also expected to have some documented option to select which field of activities is shown for option labels

What happened

I see the 2 selects. First select works The problem is the 2nd select: it has really 3 options inside it [because there are 3 records in activites], but no label is shown

image

What I've already tried to fix it

No idea, I will jump to ajax if needed

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.2.8 (cli) (built: Jul  4 2023 15:53:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies

### LARAVEL VERSION:
10.19.0.0

### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.1.1
backpack/crud: 6.1.12
backpack/generators: v4.0.2
backpack/pro: 2.0.11
backpack/theme-tabler: 1.0.12

realtebo avatar Aug 23 '23 09:08 realtebo