-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[5.4] add a "second local key" to HasManyThrough #18997
[5.4] add a "second local key" to HasManyThrough #18997
Conversation
63283ed
to
80f144b
Compare
Let's get rid off those over-mocked tests and just write a simple integration test for this relationship type. You can create a new test file for it. |
df88af4
to
f1cee1f
Compare
f1cee1f
to
798dad4
Compare
@taylorotwell done! I've recreated every test that was in the old unit test class too |
This change could create more flexible relationships and database schemas👍 |
@taylorotwell any update on this? |
I wonder if there is a better variable name than |
@taylorotwell my other suggestion would be Another option would be |
Once this is merged, I'll also PR to docs to clarify regarding the keys, I think they could use it anyway. |
@phroggyy i think this looks good but I need you to send it to master branch since it changes a method signature. |
Let's take the example in the docs, with countries, users, and posts. With the current implementation of
HasManyThrough
, we can specify the local key to use oncountries
(id
), the foreign key onusers
(country_id
), and the foreign key on the target model (user_id
onposts
). However, we can't specify the local key on the intermediary table. Consider the following scenario, where we keep a separate table for stripe accounts:In this case, if we wish to retrieve a user's transactions, we can't, because we can't specify that the key to
join
billing_accounts
andtransactions
on should bebilling_accounts.stripe_customer_id = transactions.customer_id
. Instead, Laravel assumes that we wish to use the primary key of our intermediary, something that can limit users in queries like this.