Select many to many problem

Hello! I have the following error in a Select field with many to many relationship. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sshKeys' in 'field list' The form contains:
Select::make('sshKeys')
->multiple()
->relationship('sshKeys', 'name')
->required()
->label('SSH Key'),
Select::make('sshKeys')
->multiple()
->relationship('sshKeys', 'name')
->required()
->label('SSH Key'),
This is the relationship in the model
public function sshKeys()
{
return $this->belongsToMany(SshKey::class, 'server_ssh_key');
}
public function sshKeys()
{
return $this->belongsToMany(SshKey::class, 'server_ssh_key');
}
The select field is filled successfully but when I try to save it I get the following error. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sshKeys' in 'field list' If I do my Select as multiple then everything is working properly. Any suggestion for the error?
4 Replies
LeandroFerreira
LeandroFerreira12mo ago
If I do my Select as multiple then everything is working properly. Yes, it should be multiple
Theodoros
TheodorosOP12mo ago
Are you sure about this? Is it a bug? Or is something missing from my code?
ConnorHowell
ConnorHowell12mo ago
Yeah it's because it's a Many to Many relationship, when it's not multiple it's trying to set a column on the parent record called "sshKeys" rather than attaching using the intermediate table What is it you're trying to achieve? Only allowing 1 option to be set? You could use a validation rule for that?
Theodoros
TheodorosOP12mo ago
No it is fine for me with multiple. I was wondering if it was a mistake from my side. Thanks for your answers!
Want results from more Discord servers?
Add your server