Update repeater
Flare
SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (Connection: mysql, SQL: update
artist_lead
set artist_id
= 16, artist_lead
.updated_at
= 2023-10-27 14:48:13 where = 15 and
= 15) - The error occurred at http://localhost/admin/leads/15/edit14 Replies
Is leadArtists a belongsToMany relationship? If so are you using a pivot model?
And if you are, your pivot model needs a primary key; which judging by the error I assume it doesn't have?
so that's not the case, I don't understand why it makes a where twice the identifier of my lead.
Does your artist_lead table have a primary key, like 'id'? The code you quoted won't show that. Maybe paste the migration.
I have two tables leads and artists and a pivot table artist_lead
Yeah so you’re missing a primary key on artist_lead, refer to the link I sent it’s required for the repeater to work
“Please ensure that your pivot model has a primary key column, like id, to allow Filament to keep track of which repeater items have been created, updated and deleted.”
my pivot model has two primary keys, artist_id and lead_id, I don't understand why I should add a primary key.
I need to add $table->id() in my migration ?
Usually a pivot table doesn't need a singular primary key like 'id', it uses a composite key, like you did. Because usually you aren't directly working on the pivot table itself, you are working with the target table on the other "side" of the pivot, with BelongsToMany relationships.
But when you need to work on the actual pivot itself, where you create a model for the pivot, you do need a singular primary key. Laravel (and hence Filament) doesn't natively support composite keys for models.
So the migration would need to look more like this:
The unique() isn't really needed, but you can include it if you want to enforce referential integrity.
Ok, but I use hasMany to make my repeater work, do I have to sing again for belongsToMany()?
The takeaway here is that when you need to create a model for the pivot and work directly on it, rather than simply using a pivot as part of relationships and only working on the models either "side" of the pivot, then you need a singular primary key. This is a limitation of Laravel.
Your BelongsToMany relationships should still work, as they only care about the two foreign keys.
Ok thanks for your help, I'll try that on Monday. Thanks
N/p
Solution
Just @ me if you need more help. This stuff can be confusing.
Thank you very much for your time. I hope I won't have to call you back.
@Hugh Messenger Thank you very much. it works, I didn't know laravel didn't handle composite keys, thank you very much. Bisous