I
I
Igor2019-06-23 23:35:36
Doctrine ORM
Igor, 2019-06-23 23:35:36

Can't select related objects?

class Digest
{
...
/**
     * @ORM\ManyToMany(targetEntity="Category")
     * @ORM\JoinTable(
     *     name="digest_category",
     *     joinColumns={
     *          @JoinColumn(name="digest_id", referencedColumnName="id")},
     *          inverseJoinColumns={
     *              @JoinColumn(name="category_id", referencedColumnName="id")}
     * )
     */
    private $category;
 ...
}

A third join table is created (many-to-many)
Next...
I expect to get related objects, but no.
Fatal error: Uncaught Error: Call to undefined method Doctrine\ORM\PersistentCollection::getName() in D:\OpenServer\OSPanel\domains\catalog\api\Controller\DigestController.php on line 28
$repository = new RepositoryDigest($this->em);
        $data = $repository->getOne($id);
        $category  = $data->getCategory();
        $name = $category->getName();

True, I didn't map in the "Category" entity.
Probably the question is,
How to get child elements with "Manny to Manny" relationships?
It turns out that the entity "Category" does not know about the existence of the entity "Digest"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question