MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

How to use use multiple relationships to the same model? #566

Open rantsh opened 1 year ago

rantsh commented 1 year ago

I'm writing an application where the model I'm trying to display on the table points to a "Location" model on 2 separate relationships, one for "pickup" and one for "dropoff", the issue is that when the table is displaying it shows the same value on both columns

My columns method looks like this:

    public function columns()
    {
        return [
            ...
            Column::name("pickup_location.name")->label("Pickup Location"),
            Column::name("dropoff_location.name")->label("Dropoff Location"),
            ...
        ];
    }

and the relationships on the model are:

public function pickup_location()
    {
        return $this->belongsTo(Location::class, 'pickup_location_id');
    }

    public function dropoff_location()
    {
        return $this->belongsTo(Location::class, 'dropoff_location_id');
    }

Is there something am I doing wrong here? or is it possible that this is a bug?