Doctrine - 父子查询结果关系

问题描述 投票:0回答:1

我试图用单个实体拉树数据。父母与它的子女关系。

但是,我的数据库不为空,但结果返回空数组结果。

有什么建议?

这是我的实体:(也有吸气剂和制定者)

class MyClass  
{

public function __construct()
{
    $this->children = new ArrayCollection();
}

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="MyClass", inversedBy="children")
 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
 * @Groups({"data"})
 */
private $parentAccount;

/**
 * @ORM\OneToMany(targetEntity="MyClass", mappedBy="parentAccount")
 */
private $children;

我的查询生成器:

$query = $this->getMyClassRepository()
        ->createQueryBuilder('q')
        ->leftJoin('q.parentAccount', 'q')
        ->where('q.children = :children')
        ->getQuery();

    return $query;
php doctrine-orm doctrine entity symfony-3.4
1个回答
0
投票

我认为你必须设置一个值:

   $query = $this->getMyClassRepository()
            ->createQueryBuilder('q')
            ->leftJoin('q.parentAccount', 'q')
            ->where('q.children = :children')
            ->setParameter('children', $children)

            ->getQuery();

        return $query;
© www.soinside.com 2019 - 2024. All rights reserved.