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);
});
});
}
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);
})
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!
No description
No description
No description
1 Reply
gladjanus43
gladjanus43OP2mo ago
anybody who has some ideas? Can this be a bug? Or should I just implement a custom action with the $livewire->mountedTableAction variable
Want results from more Discord servers?
Add your server