'pdo_mysql', 'user' => 'root', 'password' => 'test', 'dbname' => 'test', ); $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); $logger = new \Doctrine\DBAL\Logging\DebugStack(); $config->setSQLLogger($logger); $entityManager = EntityManager::create($dbParams, $config); /** * @Entity * @Table(name="shop") */ class Shop { /** @Id @GeneratedValue @Column(type="integer") */ public $id; /** @Column(type="string") */ public $name; /** * @OneToMany(targetEntity="Goods", mappedBy="shop") */ public $goods; public function __construct() { } } /** * @Entity * @Table(name="goods") */ class Goods { /** @Id @GeneratedValue @Column(type="integer") */ public $id; /** @Column(name="id_shop")*/ public $idShop; /** * @ManyToOne(targetEntity="Shop", inversedBy="goods", fetch="EAGER") * @JoinColumn(name="id_shop", referencedColumnName="id") **/ public $shop; /** @Column */ public $name; } $shopRepository = $entityManager->getRepository('\Shop'); $shops = $shopRepository->findAll(); echo "
\n";
//print_r($shops);

foreach ($shops as $shop) {
  //$shop->goods = null;
  //print_r($shop);


  echo $shop->id."-";
  echo count($shop->goods)."\n";
  foreach ($shop->goods as $goods) {
    echo $goods->name.";";
  }
  echo "\n";

}

foreach ($logger->queries as $q) {
  echo SqlFormatter::format($q['sql'])."
\r\n"; } ?>