File tree Expand file tree Collapse file tree 3 files changed +37
-10
lines changed Expand file tree Collapse file tree 3 files changed +37
-10
lines changed Original file line number Diff line number Diff line change 9
9
use Illuminate \Pagination \LengthAwarePaginator ;
10
10
use Illuminate \Pagination \Paginator ;
11
11
use MongoDB \BSON \ObjectID ;
12
+ use MongoDB \Driver \Exception \LogicException ;
13
+ use MongoDB \Laravel \Eloquent \Model as MongoDBModel ;
12
14
13
15
use function array_key_exists ;
14
16
use function array_values ;
@@ -195,10 +197,15 @@ public function destroy($ids = [])
195
197
/**
196
198
* Delete all embedded models.
197
199
*
198
- * @return int
200
+ * @param null $id
201
+ *
202
+ * @throws LogicException|\Throwable
203
+ *
204
+ * @note The $id is not used to delete embedded models.
199
205
*/
200
- public function delete ()
206
+ public function delete ($ id = null ): int
201
207
{
208
+ throw_if ($ id !== null , new LogicException ('The id parameter should not be used. ' ));
202
209
// Overwrite the local key with an empty array.
203
210
$ result = $ this ->query ->update ([$ this ->localKey => []]);
204
211
@@ -224,9 +231,9 @@ public function detach($ids = [])
224
231
/**
225
232
* Save alias.
226
233
*
227
- * @return Model
234
+ * @return MongoDBModel
228
235
*/
229
- public function attach (Model $ model )
236
+ public function attach (MongoDBModel $ model )
230
237
{
231
238
return $ this ->save ($ model );
232
239
}
Original file line number Diff line number Diff line change 6
6
7
7
use Illuminate \Database \Eloquent \Model ;
8
8
use MongoDB \BSON \ObjectID ;
9
+ use MongoDB \Driver \Exception \LogicException ;
10
+ use Throwable ;
11
+
12
+ use function throw_if ;
9
13
10
14
class EmbedsOne extends EmbedsOneOrMany
11
15
{
@@ -133,10 +137,16 @@ public function dissociate()
133
137
/**
134
138
* Delete all embedded models.
135
139
*
136
- * @return int
140
+ * @param ?string $id
141
+ *
142
+ * @throws LogicException|Throwable
143
+ *
144
+ * @note The $id is not used to delete embedded models.
137
145
*/
138
- public function delete ()
146
+ public function delete ($ id = null ): int
139
147
{
148
+ throw_if ($ id !== null , new LogicException ('The id parameter should not be used. ' ));
149
+
140
150
return $ this ->performDelete ();
141
151
}
142
152
Original file line number Diff line number Diff line change 8
8
use Illuminate \Database \Eloquent \Collection ;
9
9
use Illuminate \Database \Eloquent \Model as EloquentModel ;
10
10
use Illuminate \Database \Eloquent \Relations \Relation ;
11
+ use Illuminate \Database \Query \Expression ;
12
+ use MongoDB \Driver \Exception \LogicException ;
11
13
use MongoDB \Laravel \Eloquent \Model ;
14
+ use Throwable ;
12
15
13
16
use function array_merge ;
14
17
use function count ;
15
18
use function is_array ;
19
+ use function throw_if ;
16
20
17
21
abstract class EmbedsOneOrMany extends Relation
18
22
{
@@ -99,10 +103,16 @@ public function get($columns = ['*'])
99
103
/**
100
104
* Get the number of embedded models.
101
105
*
102
- * @return int
106
+ * @param Expression|string $columns
107
+ *
108
+ * @throws LogicException|Throwable
109
+ *
110
+ * @note The $column parameter is not used to count embedded models.
103
111
*/
104
- public function count ()
112
+ public function count ($ columns = ' * ' ): int
105
113
{
114
+ throw_if ($ columns !== '* ' , new LogicException ('The columns parameter should not be used. ' ));
115
+
106
116
return count ($ this ->getEmbedded ());
107
117
}
108
118
@@ -392,8 +402,8 @@ public function getQualifiedForeignKeyName()
392
402
/**
393
403
* Get the name of the "where in" method for eager loading.
394
404
*
395
- * @param \Illuminate\Database\Eloquent\Model $model
396
- * @param string $key
405
+ * @param EloquentModel $model
406
+ * @param string $key
397
407
*
398
408
* @return string
399
409
*/
You can’t perform that action at this time.
0 commit comments