Skip to content

Adds additional check of keyType to avoid using an invalid type for eager load constraints #16440

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

Closed
wants to merge 2 commits into from

Conversation

bryanashley
Copy link

@bryanashley bryanashley commented Nov 16, 2016

We've recently run into an issue eager loading an optional belongsTo relationship when our primary keys are uuids. Our issue happens when our optional belongsTo relationship is attempted to be eager loaded is not set, and a 0 is returned for the eager model key, and that is an invalid uuid. I know that it is recommended to use incrementing false to avoid this issue, but our codebase uses string uuids generated at the database layer (postgres) rather than the application layer, so technically we needed $incrementing to be set to true (since the database was handling "incrementing" in our case), however our ID type was string rather than int.

I've added this fix that will additionally check that your model's incrementing keyType is an int, before using 0 as the eager loaded model key. keyType was implemented here for another uuid related issue.

This PR is also to help resolve this issue that I opened yesterday. I believe this fix to be the safest way to address the issue without causing breaking change.

@GrahamCampbell
Copy link
Member

Please send to 5.3.

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