Php 在symfony2中使用等效方法的Laravel

Php 在symfony2中使用等效方法的Laravel,php,database,symfony,laravel,doctrine-orm,Php,Database,Symfony,Laravel,Doctrine Orm,我想从数据库中一次获取一个实体及其所有关系。在Laravel中,我们有with方法,我们可以这样使用它: 实体: class Author extends Eloquent{ public function posts(){ return $this->hasMany('post'); } } 用法: Author::with('post')->get() 我们如何在symfony2和orm中做到这一点?尝试获取:EAGER,例如

我想从数据库中一次获取一个实体及其所有关系。在Laravel中,我们有
with
方法,我们可以这样使用它:

实体:

 class Author extends Eloquent{
      public function posts(){
        return $this->hasMany('post');
      }
    }
用法:

Author::with('post')->get()

我们如何在symfony2和orm中做到这一点?

尝试
获取:EAGER
,例如,您有yml格式的作者:

App\MyBundle\Entity\Author:

  oneToMany:
    posts:
      targetEntity: Post
      mappedBy: author
      fetch: EAGER

$this->getDoctrine()->getRepository('AuthorBundle:Author')->findAll()检查延迟加载!!他想一次得到所有的实体。这不是解决办法。对于您所说的,它必须为您使用此解决方案请求的每个相关实体查询数据库,在每次代码调用中(例如在作者列表中!)都将执行渴望加载。您可以(使用fetch方法lazy od extra lazy)使用适当的select和join构建查询。(例如:选择作者,从您的捆绑中发布:作者作者左加入auhor.posts posts)