From 158bf98bec96f9cf83816f620d66304cc9b60140 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Tue, 25 Oct 2011 10:55:13 +0200 Subject: [PATCH] Throws an exception if no class found to get a connection --- src/Faker/ORM/Propel/Populator.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Faker/ORM/Propel/Populator.php b/src/Faker/ORM/Propel/Populator.php index cf50cc15..790d67a7 100644 --- a/src/Faker/ORM/Propel/Populator.php +++ b/src/Faker/ORM/Propel/Populator.php @@ -18,7 +18,7 @@ class Populator { $this->generator = $generator; } - + /** * Add an order for the generation of $number records for $entity. * @@ -38,10 +38,10 @@ class Populator $this->entities[$class] = $entity; $this->quantities[$class] = $number; } - + /** * Populate the database using all the Entity classes previously added. - * + * * @param PropelPDO $con A Propel connection object * * @return array A list of the inserted PKs @@ -56,7 +56,7 @@ class Populator $insertedEntities = array(); $con->beginTransaction(); foreach ($this->quantities as $class => $number) { - for ($i=0; $i < $number; $i++) { + for ($i=0; $i < $number; $i++) { $insertedEntities[$class][]= $this->entities[$class]->execute($con, $insertedEntities); } } @@ -64,16 +64,21 @@ class Populator if ($isInstancePoolingEnabled) { \Propel::enableInstancePooling(); } - + return $insertedEntities; } - + protected function getConnection() { // use the first connection available $class = key($this->entities); + + if (!$class) { + throw new \RuntimeException('No class found from entities. Did you add entities to the Populator ?'); + } + $peer = $class::PEER; return \Propel::getConnection($peer::DATABASE_NAME, \Propel::CONNECTION_WRITE); } -} \ No newline at end of file +}