Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add more helpful error messages on bad or insufficient morphTo data #1824
This adds more descriptive error messages when eager loading morphTo relations with bad or insufficient data. Also fixes an error about destructuring assignment when the target polymorphic couldn't be found, that prevented the actual expected error from being thrown.
The current error is only thrown when the defined morph type can't be found in any of the possible target types, but the message is a bit ambiguous because it only says that the target model can't be found.
Additionally the changes proposed in the previous PR would introduce other potential issues. It's also not very clear that having a different behavior for a polymorphic relation when calling
That PR also didn't include tests and its author was not responding.
This adds an earlier check to see if the type attribute is set at all on the model and throws an error if it isn't. This is done before even attempting to find the target model from the defined target types.
The error message in case a valid target is not found is also reworded to make it clearer.
This is a breaking change since the existing error message is different and there is a new error being thrown.
Current PR Issues
There is no check to see if the target id is set on the model since