@@ -71,7 +71,7 @@ protected function isAcrossConnections(Relation $relation)
71
71
}
72
72
73
73
/**
74
- * Compare across databases
74
+ * Compare across databases.
75
75
* @param Relation $relation
76
76
* @param string $operator
77
77
* @param int $count
@@ -91,7 +91,7 @@ public function addHybridHas(Relation $relation, $operator = '>=', $count = 1, $
91
91
$ not = in_array ($ operator , ['< ' , '<= ' , '!= ' ]);
92
92
// If we are comparing to 0, we need an additional $not flip.
93
93
if ($ count == 0 ) {
94
- $ not = !$ not ;
94
+ $ not = ! $ not ;
95
95
}
96
96
97
97
$ relations = $ hasQuery ->pluck ($ this ->getHasCompareKey ($ relation ));
@@ -123,9 +123,11 @@ protected function getHasCompareKey(Relation $relation)
123
123
protected function getConstrainedRelatedIds ($ relations , $ operator , $ count )
124
124
{
125
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 ;
126
+ $ hasNumericIndex = false ;
127
+ $ relationCount = array_count_values (array_map (function ($ id ) use ($ intHash , &$ hasNumericIndex ) {
128
+ if (! is_string ($ id ) && is_int ($ id )) {
129
+ $ hasNumericIndex = true ;
130
+ return $ intHash .$ id ;
129
131
}
130
132
return (string ) $ id ; // Convert Back ObjectIds to Strings
131
133
}, is_array ($ relations ) ? $ relations : $ relations ->flatten ()->toArray ()));
@@ -149,16 +151,22 @@ protected function getConstrainedRelatedIds($relations, $operator, $count)
149
151
});
150
152
151
153
// All related ids.
154
+ if (! $ hasNumericIndex ) {
155
+ return array_keys ($ relationCount );
156
+ }
157
+
158
+ // Has any numeric index?
152
159
return array_map (static function ($ id ) use ($ intHash ) {
153
160
if (strpos ($ id , $ intHash , 0 ) === 0 ) {
154
161
return (int ) str_replace ($ intHash , '' , $ id );
155
162
}
163
+
156
164
return (string ) $ id ;
157
165
}, array_keys ($ relationCount ));
158
166
}
159
167
160
168
/**
161
- * Returns key we are constraining this parent model's query with
169
+ * Returns key we are constraining this parent model's query with.
162
170
* @param Relation $relation
163
171
* @return string
164
172
* @throws Exception
@@ -173,10 +181,10 @@ protected function getRelatedConstraintKey(Relation $relation)
173
181
return $ relation ->getForeignKeyName ();
174
182
}
175
183
176
- if ($ relation instanceof BelongsToMany && !$ this ->isAcrossConnections ($ relation )) {
184
+ if ($ relation instanceof BelongsToMany && ! $ this ->isAcrossConnections ($ relation )) {
177
185
return $ this ->model ->getKeyName ();
178
186
}
179
187
180
- throw new Exception (class_basename ($ relation ) . ' is not supported for hybrid query constraints. ' );
188
+ throw new Exception (class_basename ($ relation ). ' is not supported for hybrid query constraints. ' );
181
189
}
182
190
}
0 commit comments