Phill Pafford
Phill Pafford

Reputation: 85368

doctrine generate entities outside of public schema

I see I can set the schema as an option in the Entity itself but is there an option to generate entities outside of the Public Schema?

Here is what works for the Public Schema

php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force
php app/console doctrine:mapping:import AcmeBlogBundle annotation
php app/console doctrine:generate:entities AcmeBlogBundle

maybe something like this:

php app/console doctrine:mapping:convert xml schema=Foo  ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force

FYI we use PostgreSQL 8.x & 9.x as our database & Symfony 2.1.3 if that matters

UPDATE:

I think this is what I'm looking for but need a way to set the schema array value:

/**
 * Sets the table name.
 *
 * @param string $name
 *
 * @return ClassMetadataBuilder
 */
public function setTable($name)
{
    $this->cm->setPrimaryTable(array('name' => $name));

    return $this;
}

UPDATE #2

I think it might be possible to set this in the connection configuration

Original Config

# Doctrine Configuration
doctrine:
    dbal:
      default_connection: my_database
      connections:
        my_database:
          driver:   pdo_pgsql
          port:     5432
          dbname:   bar
          user:     foo_user
          password: foo_pass
          charset:  UTF8

set the schema:

# Doctrine Configuration
doctrine:
    dbal:
      default_connection: my_database
      connections:
        my_database:
          driver:   pdo_pgsql
          port:     5432
          dbname:   bar/Foo
          user:     foo_user
          password: foo_pass
          charset:  UTF8

Upvotes: 2

Views: 2585

Answers (2)

Jerzy Drożdż
Jerzy Drożdż

Reputation: 448

I use Symfony 3 and I got 3 different schemas. To generate entities I use --filter option e.g:

./bin/console doctrine:mapping:import --force --filter="Schema_name." MyBundle xml

Then execute other commands to generate entities. For me work perfectly

Edit. Last thing, schema name must begin at upper case

Upvotes: 0

Chris Travers
Chris Travers

Reputation: 26464

Just to point out, if you:

ALTER USER foo_user SET search_path=foo;

Then everything not otherwise specified will be created in schema foo. If you can't solve it in Doctrine, you can solve it in PostgreSQL.

Upvotes: 0

Related Questions