Skip to content

Allow EmbedsOneOrMany::saveMany to accept a collection #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getQualifiedKeyName()
* @param string $localKey
* @param string $foreignKey
* @param string $relation
* @return EmbedsMany
* @return \Jenssegers\Mongodb\Relations\EmbedsMany
*/
protected function embedsMany($related, $localKey = null, $foreignKey = null, $relation = null)
{
Expand Down
14 changes: 8 additions & 6 deletions src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,17 @@ public function save(Model $model)
}

/**
* Attach an array of models to the parent instance.
* Attach a collection of models to the parent instance.
*
* @param array $models
* @return array
* @param \Illuminate\Database\Eloquent\Collection|array $models
* @return \Illuminate\Database\Eloquent\Collection|array
*/
public function saveMany(array $models)
public function saveMany($models)
{
array_walk($models, array($this, 'save'));

foreach ($models as $model) {
$this->save($model);
}

return $models;
}

Expand Down