Skip to content

Commit

Permalink
Add Table::saveMany().
Browse files Browse the repository at this point in the history
This allows saving multiple records in a transaction.
  • Loading branch information
ADmad committed Apr 17, 2016
1 parent 20cc328 commit 7409323
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ORM/Table.php
Expand Up @@ -1618,6 +1618,32 @@ protected function _update($entity, $data)
return $success;
}

/**
* Saves multiple records for a table.
*
* @param array $entities Entities to save.
* @param array $options Options used when calling Table::save() for each entity.
* @return bool|array False on failure, entities list on succcess.
*/
public function saveMany($entities, $options = [])
{
$return = $this->connection()->transactional(
function () use ($entities, $options) {
foreach ($entities as $entity) {
if ($this->save($entity, $options) === false) {
return false;
}
}
}
);

if ($return === false) {
return false;
}

return $entities;
}

/**
* {@inheritDoc}
*
Expand Down

0 comments on commit 7409323

Please sign in to comment.