S
S
Sergey Nizhny Novgorod2018-12-12 16:00:20
symfony
Sergey Nizhny Novgorod, 2018-12-12 16:00:20

How to request another entity in repositoty?

Hello everyone
1) There is a Room entity, it has a RoomRepository (where we write all requests, etc.).
2) There is a Door entity, it has a DoorRepository (where we write all requests, etc.).
How can I make a joint with the Door entity in the RoomRepository? How can I send it there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2018-12-12
@Decadal

$qb = $this->createQueryBuilder('room')
            ->join('room.doors', 'd')  
        return $qb->getQuery()->getResult();

what exactly is the problem?
In the Room entity, a relationship with the Door entity must be described.
The field should be called doors
, the relationship type is one-to-many
, the type of the field itself is Collection
, here's an example:
/**
     * @var \Doctrine\Common\Collections\Collection
     * @ORM\OneToMany(targetEntity="Applications\Entity\Offer", mappedBy="application", cascade={"persist"})
     */
    private $offers;

This field is in the Application entity.
call: $application->getOffers();
the Applications\Entity\Offer entity has an application field:
/**
     * @ORM\ManyToOne(targetEntity="Applications\Entity\Application", inversedBy="offers")
     * @ORM\JoinColumn(name="application_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
     */
    private $application;

call: $offer->getApplication();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question