Permalink
Browse files

Allow other connection names to be specified to getEntityManager

  • Loading branch information...
1 parent 266a4c6 commit e2bdc95263f46e22a8fce0c23bb6755a4c219f74 @mariano committed Apr 19, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 models/BaseEntity.php
View
@@ -83,12 +83,15 @@ public static function setConnectionName($connectionName) {
* Get the entity manager linked to the connection defined in the property
* `$connectionName`
*
+ * @param string $connectionName Connection name, or use the property `$connectionName` if empty
* @see IModel::getEntityManager()
* @return EntityManager entity manager
*/
- public static function getEntityManager() {
+ public static function getEntityManager($connectionName = null) {
static $entityManagers = array();
- $connectionName = static::getConnectionName();
+ if (!$connectionName) {
+ $connectionName = static::getConnectionName();
+ }
if (!isset($entityManager[$connectionName])) {
$connections = static::$_classes['connections'];
$entityManagers[$connectionName] = $connections::get($connectionName)->getEntityManager();
@@ -99,11 +102,12 @@ public static function getEntityManager() {
/**
* Get the repository for this model
*
+ * @param string $connectionName Connection name, or use the property `$connectionName` if empty
* @see IModel::getRepository()
* @return EntityRepository entity repository
*/
- public static function getRepository() {
- return static::getEntityManager()->getRepository(get_called_class());
+ public static function getRepository($connectionName = null) {
+ return static::getEntityManager($connectionName)->getRepository(get_called_class());
}
/**

0 comments on commit e2bdc95

Please sign in to comment.