-
Notifications
You must be signed in to change notification settings - Fork 288
Fix relation name infering when MorphOne/MorphMany #473
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
Conversation
@pxpm, can you add a test to prove this change? Or comment with a fixture that would demonstrate it and I can add it. |
@jasonmccreary I'v just pushed the tests for this. Please not that morphOne: \Other\Package\Order:stars, order:stars // new syntax
public function order()
{
return $this->morphOne(\Other\Package\Order::class, 'starable');
}
// old syntax
public function star()
{
return $this->morphOne(\App\Order::class, 'starable');
} When using the blueprint/src/Generators/ModelGenerator.php Line 205 in 17df0e3
It's not a BC because it only applies to this new syntax, but my question here is: should I revert and use the same way of generating the method name, or do you think it makes more sense to generate it always from the model and probably in a next major version change the old syntax to generate too from model ? Thanks, |
@pxpm, what is the "new" and "old" syntax? Can you provide examples of each. I've honestly never used Blueprint to generate polymorphic models. |
Sorry, what I meant by new syntax, is when using the As you can see in the line I pointed you out in This is not specifically to the fix provided in this PR, but in general for I am not sure if this is a
public function somethingTableName()
{
return $this->belongsTo(\App\Slash::class);
}
public function custom()
{
return $this->belongsTo(\custom::class);
} If you provide both
public function slash()
{
return $this->belongsTo(\App\Slash::class, 'other_key', 'some_key');
}
public function custom()
{
return $this->belongsTo(\custom::class, 'other_key', 'some_key');
} If changing the relation name is a feature, then the Let me know, |
I guess I don't understand the colon syntax… Did this exist before?
|
tests/fixtures/models/model-relationships-morphone-morphmany-laravel8.php
Outdated
Show resolved
Hide resolved
tests/fixtures/models/model-relationships-morphone-morphmany-laravel8.php
Outdated
Show resolved
Hide resolved
@pxpm, Ok I think this creates more symmetry between the two syntaxes. One last question, seems the example draft file now generates two methods of the same name. I'd like to fix this only in the draft file. No need to have code check this. I consider it a user error. But I want the draft file to be clear as to the intent of the test. |
@jasonmccreary as far as I know, colon syntax is supported for multiple relationship definition, I saw it in Docs https://blueprint.laravelshift.com/docs/model-relationships/ I agree that now generating two methods with the same name seems unreasonable , should I remove the "old syntax" definitions and leave only with Thanks in advance, |
Yes, or, ideally, create two separate test fixtures to demonstrate the newly added code. |
Hello @jasonmccreary Thanks for the reply and the effort providing support. I'v just updated the test to reflect this specific functionality, the tests without Thanks, |
When using fq model namespaces for relationships, the MorphOne and MorphMany need to parse the FQN into a usable string when no
key
is provided.This PR makes sure that if FQN is provided we will infer the name of the relationship from the namespace and don't use the namespace as the name.
Before:
After:
Thanks for your time and patience @jasonmccreary !