Skip to content

Relationship in "Select" not working as expect #18993

@FrancescoTerrosi

Description

@FrancescoTerrosi

Package

filament/filament

Package Version

v5.x

Laravel Version

v12+

Livewire Version

v4

PHP Version

PHP 8.4

Problem description

Select with ->relationship handling doesn't work as I would expect.

In my resource I have the following:

`

         Select::make('partner_parent_id')

               ->relationship(name: 'parent', titleAttribute: 'name')

               ->label('Partner padre')

               ->preload()

                ->searchable()

                ->loadingMessage('Caricamento partner...'),

`

The "parent" relationship is a one-to-one relationship with the same table.
The scenario is the following: I need to create entities that may have a parent-child relationship. An entity may have 0 or 1 parent. I create the first entity without assigning a parent to it as there are none. Then, I create another entity and set the previously created entity as this one's parent.
The new entity is created correctly, however it also becomes its parent's parent.

Expected behavior

I would expect that the parent's entity 'parent_id' remains unset.

Steps to reproduce

  1. Create Filament user
  2. Go to /admin panel
  3. Log in and create a new "Partner" from "Partner resource" (insert name only)
  4. Create another "Partner" and set the 'partner_parent_id' field, labeled 'Partner padre' to the previously created entity
  5. After creation, you will see that the previously created entity's parent is set to the newly created entity's id

Reproduction repository (issue will be closed if this is not valid)

https://github.com/FrancescoTerrosi/select-relationship-bug

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions