Issue with relationmanager on complicated relation (bug?)

Hi, I have a more complicated relation on my orders table. I want to retrieve all invoice lines which are connected to orders, orders.products or orders.products.attachments. This way I can display all invoice lines related to the order without navigating to the underlying resources.
The relationship is looking as follows:
    public function invoiceLines()
    {
        return $this->morphMany(InvoiceLine::class, 'invoiceable')
            ->orWhereHasMorph('invoiceable', [Product::class], function ($query) {
                $query->whereHas('order', function ($query) {
                    $query->where('id', $this->id);
                });
            })
            ->orWhereHasMorph('invoiceable', [Attachment::class], function ($query) {
                $query->whereHas('product.order', function ($query) {
                    $query->where('id', $this->id);
                });
            });
    }


This relation is retrieving the correct data in the relation table, see screenshot 1 and 2. The records do show the correct id and in the mount action inside the html it is also displaying the correct id. Whenever I open the default edit Action it always opens id 3914 for each row while the mountaction is actually trying to correctly mount the invoice line.

Now when I debug any further and make a custom action
Action::make('edit')
  ->action(function ($livewire,$record) {
      dd($livewire, $record);
  })


the $livewire->mountedTableAction is displaying the correct ID when opening. But the $record variable always passes id 3914 and therefore the edit action is always showing this record to be edited while the table is correctly displaying the data.

Is this a bug or am I missing something? Thanks!
Screenshot_2024-10-23_at_11.15.38.png
Screenshot_2024-10-23_at_11.16.04.png
Screenshot_2024-10-23_at_11.16.59.png
Was this page helpful?