Skip to content

Commit 0918c68

Browse files
Fixes has with numeric keys on hybrid relations.
1 parent b5fd237 commit 0918c68

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ protected function getHasCompareKey(Relation $relation)
122122
*/
123123
protected function getConstrainedRelatedIds($relations, $operator, $count)
124124
{
125-
$relationCount = array_count_values(array_map(function ($id) {
125+
$intHash = 'INT_RELATION_';
126+
$relationCount = array_count_values(array_map(function ($id) use ($intHash) {
127+
if (!is_string($id) && is_int($id)) {
128+
return $intHash . $id;
129+
}
126130
return (string) $id; // Convert Back ObjectIds to Strings
127131
}, is_array($relations) ? $relations : $relations->flatten()->toArray()));
128132
// Remove unwanted related objects based on the operator and count.
@@ -145,7 +149,10 @@ protected function getConstrainedRelatedIds($relations, $operator, $count)
145149
});
146150

147151
// All related ids.
148-
return array_map(static function ($id) {
152+
return array_map(static function ($id) use ($intHash) {
153+
if (strpos($id, $intHash, 0) === 0) {
154+
return (int) str_replace($intHash, '', $id);
155+
}
149156
return (string) $id;
150157
}, array_keys($relationCount));
151158
}

0 commit comments

Comments
 (0)