Commit 9443e8b4 authored by Jens Segers's avatar Jens Segers

Small tweak to embedsMany contains method

parent 00b31977
...@@ -199,14 +199,21 @@ class EmbedsMany extends Relation { ...@@ -199,14 +199,21 @@ class EmbedsMany extends Relation {
/** /**
* Indicate if a model is already contained in the embedded documents * Indicate if a model is already contained in the embedded documents
* *
* @param \Illuminate\Database\Eloquent\Model $model * @param mixed $key
* @return bool * @return bool
*/ */
public function contains(Model $model) public function contains($key)
{ {
if ($key instanceof Model)
{
$key = $key->getKey();
}
$primaryKey = $this->related->getKeyName();
foreach ($this->getEmbeddedRecords() as $record) foreach ($this->getEmbeddedRecords() as $record)
{ {
if ($record[$model->getKeyName()] == $model->getKey()) return true; if ($record[$primaryKey] == $key) return true;
} }
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment