Closed lrljoe closed 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Same issue here
The fix for this was actually a relationship level one in the model if I remember correctly! Will take a look in a week or two.
Which Laravel version are you using?
Laravel Framework 9.52.15 Livewire V2.12.6
Just to put abit more context to this
Relationships `
public function businessLicence(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(Licence::class, 'tenant_id', 'id')->latest('created_at');
}
public function deviceLicence(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(DeviceLicence::class,'tenant_id','id')->latest('created_at');
}
**Livewire Table Component**
public function configure(): void
{
return [
Column::make('ID', 'id')->isHidden(),
Column::make('Tenant Name', 'tenancy_name') ->sortable()->searchable(),
Column::make('Businesses used','businessLicence.current_used_total')->sortable()->unclickable()
->deselected()->searchable()
]
}
public function columns(): array
{
return [
Column::make('ID', 'id')->isHidden(),
Column::make('Tenant Name', 'data->tenancy_name') ->sortable()->searchable(),
Column::make('Business used','businessLicence.current_used_total')->sortable()->unclickable()
->deselected()->searchable()]
`
public function builder(): Builder
{
return Tenant::query()
->with(['businessLicence','deviceLicence']);
}
I have multiple references to the tenant id , within the business licence table (Licence::).
if i dd(Tenant::query() ->with(['businessLicence','deviceLicence'])->get());
I see the last records in the relationships as expected and no duplication
Any help would be greatly appreciated
@rappasoft can you help me how to fix this
i have same issue there in hasOne relationship only
Originally from dirtbikr
Example
User
model has a relationship with aPurchase
model:Users may have many purchases, outside of the package, the latestPurchase relationship correctly returns one result. Within the package, it returns as many purchases as exist.
Query outside of the package is as follows: An initial select for the users:
Then a self-joined query for the latest purchase:
Query within the package is as follows:
Example repo: https://github.com/lrljoe/livewire-tables-latestofmanyissue/tree/Showing-Issue Interim Fix Interim fix is as follows, with recommendation to use Builder to eager load the relationship. https://github.com/lrljoe/livewire-tables-latestofmanyissue/blob/Fixed-Issue/app/Http/Livewire/UserTable.php
Originally posted by @dirtbikr in https://github.com/rappasoft/laravel-livewire-tables/discussions/1004