RelationManager select relationship with multiple(), Duplicate entry on update
Hi, the following code in a RelationManager:
With a belongsToMany from both Models to each other. When creating, there is no problem, but when updating and add more domains, I get:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'assets_content_domain.PRIMARY'
insert into
Shouldn't it automatically manage that the record I am updating already exists? It's a bug?
Thanks
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('domains')
->relationship('domains','domain')
->multiple()
->preload(),With a belongsToMany from both Models to each other. When creating, there is no problem, but when updating and add more domains, I get:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'assets_content_domain.PRIMARY'
insert into
assets_content_domain (assets_content_id, domain_id) values (1, 2)Shouldn't it automatically manage that the record I am updating already exists? It's a bug?
Thanks
Solution
Ahh I see you have a primary key set on assets_content_id and you are setting it wrong for a composite primary key. Try: