Skip to content

Instantly share code, notes, and snippets.

@micha149
Last active August 18, 2022 21:37
Show Gist options
  • Save micha149/9115366 to your computer and use it in GitHub Desktop.
Save micha149/9115366 to your computer and use it in GitHub Desktop.
Example command to get all entity association mappings. #symfony2 #doctrine2
<?php
namespace Esel\ContentBundle\Command;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class FindEntityRelationsCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('entity:relations')
->setDescription('Lists association data for entities');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
$metadata = $em->getMetadataFactory()->getAllMetadata();
/** @var ClassMetadata $classMeta*/
foreach($metadata as $classMeta) {
ld($classMeta->getAssociationMappings());
}
}
}
@danbettles
Copy link

That came in handy. Thanks 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment