@@ -71,7 +71,7 @@ protected function isAcrossConnections(Relation $relation)
7171 }
7272
7373 /**
74- * Compare across databases
74+ * Compare across databases.
7575 * @param Relation $relation
7676 * @param string $operator
7777 * @param int $count
@@ -91,7 +91,7 @@ public function addHybridHas(Relation $relation, $operator = '>=', $count = 1, $
9191 $ not = in_array ($ operator , ['< ' , '<= ' , '!= ' ]);
9292 // If we are comparing to 0, we need an additional $not flip.
9393 if ($ count == 0 ) {
94- $ not = !$ not ;
94+ $ not = ! $ not ;
9595 }
9696
9797 $ relations = $ hasQuery ->pluck ($ this ->getHasCompareKey ($ relation ));
@@ -123,9 +123,11 @@ protected function getHasCompareKey(Relation $relation)
123123 protected function getConstrainedRelatedIds ($ relations , $ operator , $ count )
124124 {
125125 $ 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 ;
129131 }
130132 return (string ) $ id ; // Convert Back ObjectIds to Strings
131133 }, is_array ($ relations ) ? $ relations : $ relations ->flatten ()->toArray ()));
@@ -149,16 +151,22 @@ protected function getConstrainedRelatedIds($relations, $operator, $count)
149151 });
150152
151153 // All related ids.
154+ if (! $ hasNumericIndex ) {
155+ return array_keys ($ relationCount );
156+ }
157+
158+ // Has any numeric index?
152159 return array_map (static function ($ id ) use ($ intHash ) {
153160 if (strpos ($ id , $ intHash , 0 ) === 0 ) {
154161 return (int ) str_replace ($ intHash , '' , $ id );
155162 }
163+
156164 return (string ) $ id ;
157165 }, array_keys ($ relationCount ));
158166 }
159167
160168 /**
161- * Returns key we are constraining this parent model's query with
169+ * Returns key we are constraining this parent model's query with.
162170 * @param Relation $relation
163171 * @return string
164172 * @throws Exception
@@ -173,10 +181,10 @@ protected function getRelatedConstraintKey(Relation $relation)
173181 return $ relation ->getForeignKeyName ();
174182 }
175183
176- if ($ relation instanceof BelongsToMany && !$ this ->isAcrossConnections ($ relation )) {
184+ if ($ relation instanceof BelongsToMany && ! $ this ->isAcrossConnections ($ relation )) {
177185 return $ this ->model ->getKeyName ();
178186 }
179187
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. ' );
181189 }
182190}
0 commit comments