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);
                        }
                    })


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?
Screenshot_2023-09-28_at_10.44.06_AM.png
Was this page helpful?