Skip to content

Instantly share code, notes, and snippets.

@micha149
Last active August 18, 2022 21:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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());
}
}
}
@romainlaisne
Copy link

Hi,

What is this ld() function?

@swarshah
Copy link

The ld() functions calls the ladybug_dump function.

@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