Relation Manager Wrong Record Using Union

I have a special case for a relation manager where I override the getTableQuery and I return a union of two tables for the relation manager (two different types of orders for the OrdersRelationManager - I want them all in one place). The query works fine and shows the union properly I use: return $cateringOrders->union($externalOrders); The issue is when I need to edit one of the orders from $externalOrders. No matter what I do, it only returns the record for the first record of $externalOrders. Here is my custom edit button:
Action::make('customEdit')
// other customizations
->form(function (RelationManager $livewire, $record) {
$class = new OrdersRelationManager;
if($record->type == 'catering') {
$record = Order::find($record->id);
return $class->getEditForm($record);
} else {
$record = ExternalOrder::find($record->id);
return $class->getEditExternalOrderForm($record);
}
})
Action::make('customEdit')
// other customizations
->form(function (RelationManager $livewire, $record) {
$class = new OrdersRelationManager;
if($record->type == 'catering') {
$record = Order::find($record->id);
return $class->getEditForm($record);
} else {
$record = ExternalOrder::find($record->id);
return $class->getEditExternalOrderForm($record);
}
})
What makes this stranger is that the values in the table (i.e.: status - see screenshot) are correct. So it is displaying the proper data in each row but it's using the wrong record when I click on Edit. If I switch the union and use return $externalOrders->union($cateringOrders); I get the same issue, but with the catering orders in this case. Why would the data in each row display correctly but the buttons in the row use the wrong record?
No description
2 Replies
bwurtz999
bwurtz999OP15mo ago
Still stuck on this issue. Anyone have any ideas what could be going on here? Thanks in advance!
DrByte
DrByte15mo ago
Without source-diving into the component and template code, I don't have any answer. But the first thing I'd be inclined to do is dump out a bunch of data into those rows to see what clues might be found in splitting a bunch of your logic apart into bespoke pieces, in an effort to see what the component is latching onto. On the surface, based on the code you posted, I don't see why it would be a problem. Therefore gotta dig more into what's happening internally. That's where I'd start anyway. (I know filament caches a few field state details, but I'm not certain that's what's involved here.)
Want results from more Discord servers?
Add your server