The error you’re seeing:
SQLSTATE[HY000]: General error: 20 datatype mismatch (Connection: sqlite, SQL: update "authors" set "id" = ?, "updated_at" = 2025-09-07 20:48:50 where "authors"."id" = 6 and "authors"."id" is not null)
suggests that Filament is trying to update the id column of the authors table, which is not what you want. This usually happens due to a misconfiguration in the relationship definition and how Filament is handling the select field.
What’s Happening?
-
Your
composerrelationship is defined as:public function composer(): HasOne { return $this->HasOne(Author::class,'id','composer_id'); }This means: "This LibraryItem has one Author, where the Author's
idmatches LibraryItem'scomposer_id." -
In your Filament form, you use:
->relationship('composer')This tells Filament to use the
composerrelationship for this select field. However, Filament expects aBelongsTorelationship for this kind of select, not aHasOne.
Why is it trying to update the authors table?
Because with a HasOne relationship, Filament thinks the current model (LibraryItem) is the parent, and it tries to update the related model (Author) to point back to the parent. That’s why it tries to update the id of the author, which is not what you want.
Solution
You should define the relationship as a BelongsTo in your LibraryItem model:
public function composer(): BelongsTo
{
return $this->belongsTo(Author::class, 'composer_id');
}
- This means: "This LibraryItem belongs to an Author, referenced by
composer_id."
Now, your Filament select field will work as expected, and it will set the composer_id on the library_items table, not try to update the authors table.
Summary of Steps
-
Update your model relationship:
use Illuminate\Database\Eloquent\Relations\BelongsTo; public function composer(): BelongsTo { return $this->belongsTo(Author::class, 'composer_id'); } -
Keep your Filament select field as is:
Select::make('composer_id') ->label('Composer') ->searchable(['first_name', 'last_name']) ->preload() ->editOptionForm(Author::getForm()) ->createOptionForm(Author::getForm()) ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->last_name}, {$record->first_name} ") ->relationship('composer')
After this change, Filament will correctly handle the relationship and update the composer_id on your LibraryItem record, not the authors table.
Let me know if you have any further questions!