Hello, I have a relation like this :
A
- id
- fields
- X
B
- same id as A
- fields
C
- same id as A
- fields
So when we get a A item, following what's inside field X we can have a relation to B or C.
So I have two relation like this in A :
class A extends Eloquent {
// ...
public function b()
{
return $this->hasOne(B::class, 'id');
}
public function c()
{
return $this->hasOne(C::class, 'id');
}
}
I'm wondering if it's possible to do something that allow me to make one declaration like this
public function bc()
{
return $this->relationOr('X=b', $this->hasOne(B::class, 'id'), 'X=c', $this->hasOne(C::class, 'id'));
}
I supposed you got the idea. This kind of way to do it is extract from doctrine InheritanceType("JOINED") in the declaration of table. thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community