MedicOneSystems / MedicOneSystems/livewire-datatables
How to use use multiple relationships to the same model?
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two relationships and the columns shown in the issue, then inspect how relationship-based columns are resolved. Done means pickup_location.name and dropoff_location.name display their respective related Location values instead of the same value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100