Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MalikUmair001 opened this issue May 1, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@MalikUmair001
Copy link

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 MalikUmair001 added the bug Something isn't working label May 1, 2024
@MalikUmair001
Copy link
Author

/**
* Get buyer
*
* @return object
*/
public function buyer()
{
return $this->belongsTo(User::class, 'buyer_id')->withTrashed();
}

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

@lrljoe
Copy link
Sponsor Collaborator

lrljoe commented May 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants