Doctrine, tell which tables to work with
When working with Doctrine2 DBAL, sometimes we work with a shared database model in which there are some support tables that we do not want in our Doctrine ORM model.
Imagine that you have an schema with following tables:
- recipes
- ingredients
- posts
- queue
For excluding, or including, some database tables for mappings we could use 'setFilterSchemaAssetsExpression' method.
/** @var \Doctrine\DBAL\Connection $connection */
$config = $connection->getConfiguration();
// for excluding an specific table
$config->setFilterSchemaAssetsExpression('/^(?!table_name_to_exclude).*$/');
When we try to generate Entities from database, with:
$config->setFilterSchemaAssetsExpression('/^(recipes|ingredients).*$/');
Doctrine ORM will only generate 'Recipes' and 'Ingredients' class entities and will exclude 'posts' and 'queue' tables.
Written by Xavier Fornés
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Doctrine2
Authors
Related Tags
#doctrine2
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#