How can I get access to related entities with Symfony doctrine?

I try to find all documents that are related to my product:

public function findDocumentsRelatedToProduct($id) {
        return $this->createQueryBuilder('products')
                        ->leftJoin('products.documents', 'pd')
                        ->where("products.id = :id")
                        ->setParameter(':id', $id)
                        ->getQuery()
                        ->execute();

}

$products = $this->em->getRepository('AppEntityProducts')->findDocumentsRelatedToProduct($id);

foreach ($products as $key => $value) {
    dump($value->getDocuments()->getId());
}

But I get the error message:

Attempted to call an undefined method named "getId" of class "DoctrineORMPersistentCollection".

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *