@maticl
@maticl
FFilament
Created by @maticl on 11/8/2024 in #❓┊help
RelationManager table action always injects the same record
So after some more debugging, i found the issue. It was in the User relationship to the auditLogs. Since I have two morphs fields in auditLog (parent and related), this specific relationship queries by both of them:
public function allAuditLogs(): MorphMany
{
return $this->morphMany(AuditLog::class, 'parent')
->orWhere(function ($query) {
$query->where('related_type', $this->getMorphClass())
->where('related_id', $this->id);
});
}
public function allAuditLogs(): MorphMany
{
return $this->morphMany(AuditLog::class, 'parent')
->orWhere(function ($query) {
$query->where('related_type', $this->getMorphClass())
->where('related_id', $this->id);
});
}
This was not working with the table actions. The table itself was OK, just the actions were not working. I don't specifically like this solution, as it seems wrong, but I don't have the time to figure out the proper solution. Any tips are welcome. I changed it to the following, and now it's working:
public function allAuditLogs(): MorphMany
{
return $this->morphMany(AuditLog::class, 'parent')
->where(function ($query) {
$query->where(function ($query) {
$query->where('related_type', $this->getMorphClass())
->where('related_id', $this->id);
})->orWhere(function ($query) {
$query->where('parent_type', $this->getMorphClass())
->where('parent_id', $this->id);
});
});
}
public function allAuditLogs(): MorphMany
{
return $this->morphMany(AuditLog::class, 'parent')
->where(function ($query) {
$query->where(function ($query) {
$query->where('related_type', $this->getMorphClass())
->where('related_id', $this->id);
})->orWhere(function ($query) {
$query->where('parent_type', $this->getMorphClass())
->where('parent_id', $this->id);
});
});
}
3 replies