File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
src/Jenssegers/Mongodb/Relations Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -199,14 +199,21 @@ public function count()
199
199
/**
200
200
* Indicate if a model is already contained in the embedded documents
201
201
*
202
- * @param \Illuminate\Database\Eloquent\Model $model
202
+ * @param mixed $key
203
203
* @return bool
204
204
*/
205
- public function contains (Model $ model )
205
+ public function contains ($ key )
206
206
{
207
+ if ($ key instanceof Model)
208
+ {
209
+ $ key = $ key ->getKey ();
210
+ }
211
+
212
+ $ primaryKey = $ this ->related ->getKeyName ();
213
+
207
214
foreach ($ this ->getEmbeddedRecords () as $ record )
208
215
{
209
- if ($ record [$ model -> getKeyName () ] == $ model -> getKey () ) return true ;
216
+ if ($ record [$ primaryKey ] == $ key ) return true ;
210
217
}
211
218
212
219
return false ;
You can’t perform that action at this time.
0 commit comments