Skip to content

Improve error handling on unsupported hybrid queries #3404

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

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from

Conversation

paulinevos
Copy link
Collaborator

Hybrid belongs-to-many relationships are not supported for query constraints. However, the support check was done downstream of a bunch of Eloquent stuff, resulting in the user getting an exception that didn't tell them anything about the usage being unsupported.

This moves that check further up the chain so that the user is alerted to the lack of support before we do anything else.

Checklist

  • Add tests and ensure they pass

Hybrid belongs-to-many relationships are not supported for query
constraints. However, the support check was done downstream of a bunch
of Eloquent stuff, resulting in the user getting an exception that
didn't tell them anything about the usage being unsupported.

This moves that check further up the chain so that the user is alerted
to the lack of support before we do anything else.
@paulinevos paulinevos requested a review from a team as a code owner June 12, 2025 08:49
@paulinevos paulinevos requested a review from GromNaN June 12, 2025 08:49
@paulinevos paulinevos enabled auto-merge (squash) June 12, 2025 09:04
return;
}

throw new Exception(class_basename($relation) . ' is not supported for hybrid query constraints.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can be more specific, this is a logic exception (developer fault).

Suggested change
throw new Exception(class_basename($relation) . ' is not supported for hybrid query constraints.');
throw new \LogicException(class_basename($relation) . ' is not supported for hybrid query constraints.');

*
* @throws Exception
*/
public function assertHybridRelationSupported(Relation $relation): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this method don't need to be public, make it private so that we don't have to maintain backward compatibility on it.

Suggested change
public function assertHybridRelationSupported(Relation $relation): void
private function assertHybridRelationSupported(Relation $relation): void

In PHPLIB we enforce private methods to be at after the public ones, I think that would be a good idea for this method to move it at the end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I made it public cause I thought the other usage was outside of the class (it's not)

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

Successfully merging this pull request may close these issues.

2 participants