Skip to content

[Bug]: using same relationship only last saved #123

Closed
@dgironella

Description

@dgironella

What happened?

If you use two SelectTree with same relationship but a diferent modifyQueyUsing when save only last SelectTree is saved

How to reproduce the bug

    SelectTree::make('institucions')
                    ->label('Institucions')
                    ->relationship('institucions','titol', 'parent_id',modifyQueryUsing: fn($query) => $query->where('tipus', SubCodeEnum::Institucio))
                    ->searchable()
                    ->required()->columnSpanFull()
                    ->enableBranchNode()
                    ->helperText('Podeu seleccionar més d\'una institució, deixar buit per tots'),
                SelectTree::make('beneficiaris')
                    ->label('Beneficiaris')
                    ->relationship('beneficiaris','titol', 'parent_id',modifyQueryUsing: fn($query) => $query->where('tipus', SubCodeEnum::Beneficiaris))
                    ->searchable()
                    ->required()->columnSpanFull()
                    ->enableBranchNode()
                    ->helperText('Podeu seleccionar més d\'un beneficiari, deixar buit per tots'),


And on Client Model relationship



public function beneficiaris(): belongsToMany
    {
        return $this->belongsToMany(Subcode::class, 's_code_to_clients', 'client_id', 'subcode_id')->where('tipus', SubCodeEnum::Beneficiaris);
    }

    public function institucions(): belongsToMany
    {
        return $this->belongsToMany(Subcode::class, 's_code_to_clients', 'client_id', 'subcode_id')->where('tipus', SubCodeEnum::Institucio);
    }

Package Version

3.1

PHP Version

8.2

Laravel Version

11.9

Which operating systems does with happen with?

Linux

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions