-
Notifications
You must be signed in to change notification settings - Fork 1.4k
getConstrainedRelatedId
method not returning ids as string if key is a numeric string
#2182
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
Comments
I could get it working by doing this fix:
And later,
On the |
getConstrainedRelatedId
method not returning array_keys as string if numeric keysgetConstrainedRelatedId
method not returning ids as string if key is a numeric string
What is the root cause to create document with string |
Our projects use internally My PR to fix stopped on hybrid relations, the same happens with @danielsouzaaf solution, because of MySQL integer id on mongo document. |
I vote no for this custom fix which might just slow down for everyone. That's it. Custom code for only fixing this in your projects? Thanks! |
Is not only for our project, but is a bug that could happen on others with numeric keys when using ‘has’ methood. My second commit fixes the bug with hybrid relations. |
There are bugs that are exactly created by this type of custom code. Fix over on a fix. What if I have geo type _id? Does your code fix it? No. If its going to be fixed then a global fix should be created for casted attributes as outlined here #1974 (comment). Thanks! |
Aye, I understand your point but working with And my point here is with relation keys, I do not see a usage of geotype as PK/FK. I'm right? |
Sorry, missed that this is the really old version. Your PR was pushed to master which is 3.8. I still don't have a strong positive opinion about merging that PR. I can understand you need to fix this but also don't forget there are a lot of people using it. Making such changes for fixing a little bit of question that it might create some bugs later. Let me ask kindly @Smolevich for his thoughts. Thanks! |
No problem, we're here to find the best solution for everyone! I created to PR to master, because I see you backporting PRs to older versions as well. |
Yup, not everyone could upgrade to the next Laravel version in one click. It takes time and there is no reason why fixes should be in a newer version only. Thanks! |
VERSION: 3.8.5 We have noticed the exact same issue. Our Previous attempt, broken: // App\Models\User.php
public function getOrganizationsAttribute() {
return Organization::whereHas('userRoles', function ($userRoles) {
$userRoles->where('user_id', $this->id);
})->get()->sortBy('name');
} New attempt, functional: // App\Models\User.php
public function getOrganizationsAttribute() {
return $this->userRoles->pluck('organization')->unique()->sortBy('name');
} Essentially, don't use |
Description:
When using a whereHas filter, if the field under the whereHas clause is a string with a numeric value,
getConstrainedRelatedIds
on theQueriesRelationships
trait is returning the keys as numeric instead of string. With that, if the column in the where clause is a string, it fails.Steps to reproduce
_id
PK as string and another field for testing purposes, e.g:active: true
.Expected behaviour
It should return the two childs
Actual behaviour
None child is returned.
Logs:
Insert log.txt here (if necessary)The text was updated successfully, but these errors were encountered: