rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.7k stars 319 forks source link

[Bug]: Relationship not working if we have multiple relationship with same table #1712

Open MalikUmair001 opened 2 months ago

MalikUmair001 commented 2 months ago

What happened?

public function seller() { return $this->belongsTo(User::class, 'seller_id')->withTrashed(); }

/**
 * Get order items
 *
 * @return object
 */
public function items()
{
    return $this->hasMany(OrderItem::class, 'order_id');
}

Column::make("Buyer", "buyer.email")
            // ->view('datatable.views.orders.table-order-buyer')
            ->sortable(),

        Column::make("Seller", "seller.email")
            // ->view('datatable.views.orders.table-order-seller')
            ->sortable(),

It returns same value for both columns

How to reproduce the bug

public function seller() { return $this->belongsTo(User::class, 'seller_id')->withTrashed(); }

/**
 * Get order items
 *
 * @return object
 */
public function items()
{
    return $this->hasMany(OrderItem::class, 'order_id');
}

Column::make("Buyer", "buyer.email")
            // ->view('datatable.views.orders.table-order-buyer')
            ->sortable(),

        Column::make("Seller", "seller.email")
            // ->view('datatable.views.orders.table-order-seller')
            ->sortable(),

It returns same value for both columns

Package Version

No response

PHP Version

None

Laravel Version

No response

Alpine Version

No response

Theme

None

Notes

No response

Error Message

No response

MalikUmair001 commented 2 months ago

/**

lrljoe commented 1 month ago

So I suspect it's due to how the package creates the joins dynamically.

Please confirm which version of the Tables Package, Laravel, Livewire you're using

Can you please also share: 1) The full code for your Table Component 2) The relevant elements from the Model that is being used in the Table as the "primary model", (i.e. the relationships)

Please wrap it in the script tags (three ` marks)

I can then try to replicate it on my end and give you some options, or fix any bugs.

stale[bot] commented 3 weeks 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.