-
Notifications
You must be signed in to change notification settings - Fork 3
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
Missing bindings on eager loads when using string primary keys #5
Comments
Hi @a-drew,
Does this solved the Issue in your case? previously while development, I ran into lots of problems when bindings were manually pushed into the Queries. |
Hey @kingmaker-agm, I've setup an override in one of my project and it solved the issue, but I admit I haven't experimented with particularly complex queries just the following:
BelongsToManySelf Relation, used by Article::related()
|
Hi @a-drew, Can you explain your code a bit (DB Schema with Column types, Eloquent Relations & the Queries)? your input can help me to improve the package. I will try to look into the Issue on my free time. |
hey @kingmaker-agm, first off happy new year 🎉🎉 Here's a basic example of what I was doing. 3 tables and only 2 models: Articles and Categories. Articles have a SchemaModelsArticle.php
Category.php
Example Query Usage:Example queries would look like:
I would use eager-loading, turning said query into:
This is where we start running into issues. We reach the
When the key type is a string, the normal Output Of Eagerloaded Queries:here's some tinker output where I dump the whole query and with its bindings before exiting out of my version of ❯ without addBindings, using integer key type on the models
❯ without
❯ key type string and one
❯ key type string with both
|
I've found an edge case for users with string primary keys, where the eager loads won't behave as expected.
When using auto-increment keys, you don't need bindings at all but when your models are using UUIDs the eager load won't build the correct query.
I traced it down to this method:
laravel-many-to-many-self/src/BelongsToManySelf.php
Lines 144 to 163 in 797c689
I believe using
$this->addBindings($keys)
twice on lines 158 / 162, for both whereIn constraints, should solve this.The text was updated successfully, but these errors were encountered: