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] Relationship field are not displaying good selected values on setupUpdateOperation #5378

Open
Astriel opened this issue Nov 22, 2023 · 1 comment
Assignees

Comments

@Astriel
Copy link

Astriel commented Nov 22, 2023

Bug report

What I did

I've created a CrudController and the UpdateOperation with a relationship field from a 1 <> n relation.

 CRUD::field([
            'name'          => 'language_id',
            'type'          => 'relationship',
            'entity'        => 'language', // the method that defines the relationship in your Model
            'label'         => __('backpack.language'),
            'hint'          => __('backpack.create_group_language'),
        ]);

I've already checked all my relations, and they are working properly

What I expected to happen

On the update form / screen I was expecting to have the good ID selected in the relationship field.

If the field is : relationship, the first value of the select is selected, otherwise the good value is displayed

What happened

It is not working with the relationship field, but working with the select field. The field / value that is supposed to be selected is not the good one.

image

What I've already tried to fix it

Switching from relationship field to the select field.

        CRUD::field([
            'name'          => 'language_id',
            'type'          => 'select',
            'entity'        => 'language', // the method that defines the relationship in your Model
            'label'         => __('backpack.language'),
            'hint'          => __('backpack.create_group_language'),
        ]);

image

Is it a bug in the latest version of Backpack?

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

Backpack, Laravel, PHP, DB version

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

` ### PHP VERSION:
PHP 8.2.11 (cli) (built: Sep 26 2023 15:25:31) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.11, Copyright (c) Zend Technologies

LARAVEL VERSION:

10.33.0.0

BACKPACK PACKAGE VERSIONS:

backpack/basset: 1.2.2
backpack/crud: 6.3.0
backpack/devtools: 2.0.3
backpack/generators: v4.0.2
backpack/logmanager: v5.0.1
backpack/permissionmanager: 7.1.1
backpack/pro: 2.0.18
backpack/theme-coreuiv2: 1.2.2
backpack/theme-coreuiv4: 1.1.1`

@Astriel Astriel added the triage label Nov 22, 2023
@pxpm
Copy link
Contributor

pxpm commented Nov 23, 2023

Hey @Astriel what kind of relationship is that ? BelongsTo ?

Can you try just with the relation name as the field name to check if it does any difference ?

 CRUD::field('language')->label(__('backpack.language')->hint(__('backpack.create_group_language'));

Any chance you have a resources/views/vendor/backpack/pro/fields/relationship.blade.php custom in your app ?

I was about to ask you if you could reproduce it in our demo, and I noticed that in our demo the BelongsTo relationship was not properly working. I thought you were right, but in the end it was a mistake in our end.

We had two fields using the same relationship, so the value of one was overwriting the other.

I've fixed it in Laravel-Backpack/demo#581 and belongsTo relations seems to be working just fine, so I will add that you could check:

  • that you have not two fields for the same relationship.
  • that you have the language_id in your $fillable array in the model.

Let me know if that helps.

Cheers

@pxpm pxpm self-assigned this Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants