@@ -13,15 +13,15 @@ class Builder extends EloquentBuilder
1313 * @var array
1414 */
1515 protected $ passthru = [
16- 'toSql ' , 'lists ' , ' insert ' , 'insertGetId ' , 'pluck ' ,
16+ 'toSql ' , 'insert ' , 'insertGetId ' , 'pluck ' ,
1717 'count ' , 'min ' , 'max ' , 'avg ' , 'sum ' , 'exists ' , 'push ' , 'pull ' ,
1818 ];
1919
2020 /**
2121 * Update a record in the database.
2222 *
23- * @param array $values
24- * @param array $options
23+ * @param array $values
24+ * @param array $options
2525 * @return int
2626 */
2727 public function update (array $ values , array $ options = [])
@@ -40,7 +40,7 @@ public function update(array $values, array $options = [])
4040 /**
4141 * Insert a new record into the database.
4242 *
43- * @param array $values
43+ * @param array $values
4444 * @return bool
4545 */
4646 public function insert (array $ values )
@@ -59,8 +59,8 @@ public function insert(array $values)
5959 /**
6060 * Insert a new record and get the value of the primary key.
6161 *
62- * @param array $values
63- * @param string $sequence
62+ * @param array $values
63+ * @param string $sequence
6464 * @return int
6565 */
6666 public function insertGetId (array $ values , $ sequence = null )
@@ -97,9 +97,9 @@ public function delete()
9797 /**
9898 * Increment a column's value by a given amount.
9999 *
100- * @param string $column
101- * @param int $amount
102- * @param array $extra
100+ * @param string $column
101+ * @param int $amount
102+ * @param array $extra
103103 * @return int
104104 */
105105 public function increment ($ column , $ amount = 1 , array $ extra = [])
@@ -127,9 +127,9 @@ public function increment($column, $amount = 1, array $extra = [])
127127 /**
128128 * Decrement a column's value by a given amount.
129129 *
130- * @param string $column
131- * @param int $amount
132- * @param array $extra
130+ * @param string $column
131+ * @param int $amount
132+ * @param array $extra
133133 * @return int
134134 */
135135 public function decrement ($ column , $ amount = 1 , array $ extra = [])
@@ -155,19 +155,21 @@ public function decrement($column, $amount = 1, array $extra = [])
155155 /**
156156 * Add the "has" condition where clause to the query.
157157 *
158- * @param \Illuminate\Database\Eloquent\Builder $hasQuery
159- * @param \Illuminate\Database\Eloquent\Relations\Relation $relation
160- * @param string $operator
161- * @param int $count
162- * @param string $boolean
158+ * @param \Illuminate\Database\Eloquent\Builder $hasQuery
159+ * @param \Illuminate\Database\Eloquent\Relations\Relation $relation
160+ * @param string $operator
161+ * @param int $count
162+ * @param string $boolean
163163 * @return \Illuminate\Database\Eloquent\Builder
164164 */
165165 protected function addHasWhere (EloquentBuilder $ hasQuery , Relation $ relation , $ operator , $ count , $ boolean )
166166 {
167167 $ query = $ hasQuery ->getQuery ();
168168
169169 // Get the number of related objects for each possible parent.
170- $ relationCount = array_count_values ($ query ->lists ($ relation ->getHasCompareKey ()));
170+ $ relationCount = array_count_values (array_map (function ($ id ) {
171+ return (string )$ id ; // Convert Back ObjectIds to Strings
172+ }, $ query ->pluck ($ relation ->getHasCompareKey ())));
171173
172174 // Remove unwanted related objects based on the operator and count.
173175 $ relationCount = array_filter ($ relationCount , function ($ counted ) use ($ count , $ operator ) {
@@ -207,7 +209,7 @@ protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $o
207209 /**
208210 * Create a raw database expression.
209211 *
210- * @param closure $expression
212+ * @param closure $expression
211213 * @return mixed
212214 */
213215 public function raw ($ expression = null )
@@ -219,17 +221,13 @@ public function raw($expression = null)
219221 if ($ results instanceof Cursor) {
220222 $ results = iterator_to_array ($ results , false );
221223 return $ this ->model ->hydrate ($ results );
222- }
223-
224- // Convert Mongo BSONDocument to a single object.
224+ } // Convert Mongo BSONDocument to a single object.
225225 elseif ($ results instanceof BSONDocument) {
226226 $ results = $ results ->getArrayCopy ();
227- return $ this ->model ->newFromBuilder ((array ) $ results );
228- }
229-
230- // The result is a single object.
227+ return $ this ->model ->newFromBuilder ((array )$ results );
228+ } // The result is a single object.
231229 elseif (is_array ($ results ) and array_key_exists ('_id ' , $ results )) {
232- return $ this ->model ->newFromBuilder ((array ) $ results );
230+ return $ this ->model ->newFromBuilder ((array )$ results );
233231 }
234232
235233 return $ results ;
0 commit comments