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

Relate two different foreign keys to single local key #174

Open
KonradHambuch opened this issue Apr 9, 2024 · 0 comments
Open

Relate two different foreign keys to single local key #174

KonradHambuch opened this issue Apr 9, 2024 · 0 comments

Comments

@KonradHambuch
Copy link

I have a table exchanges that has standard_parcel_id and return_parcel_id. I want my Parcel model have an Exchange, so my relationship would be:

public function exchange(){
        return $this->hasOne(Exchange::class, ['standard_parcel_id', 'return_parcel_id'], ['id', 'id']);
    }

In this case no parcel finds its exchanges table record. If I use only one 'id', it will work for the first foreign key, but not for the second one. So in this case:

public function exchange(){
        return $this->hasOne(Exchange::class, ['standard_parcel_id', 'return_parcel_id'], ['id']);
    }

standard parcels find their Exchange, but return parcels do not.

Is there a workaround here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant