G
G
gitdev2018-10-02 18:12:28
symfony
gitdev, 2018-10-02 18:12:28

How to organize bidirectional communication in Symfony 4?

You need to get all agents for realty.
Realty can have any number of Agents. Connected through AgentRealty.

class Realty
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}

class Agent
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}

/**
 * AgentRealty
 *

 * @ORM\Entity
 * @ORM\Table(name="agent_realties")
 *
 */
class AgentRealty
{
    /**
     * @ORM\OneToOne(targetEntity="App\Metrag\AppBundle\Entity\Realty")
     * @ORM\JoinColumn(name="realty_id", referencedColumnName="id" )
     * @ORM\Id
     */
    private $realty;

    /**
     * @ORM\OneToOne(targetEntity="App\Metrag\AppBundle\Entity\Agent")
     * @ORM\JoinColumn(name="agent_id", referencedColumnName="id" )
     * @ORM\Id
     */
    private $agent;

    public function getRealty(): ?Realty
    {
        return $this->realty;
    }

    public function setRealty(?Realty $realty): self
    {
        $this->realty = $realty;

        return $this;
    }

    public function getAgent(): ?Agent
    {
        return $this->agent;
    }

    public function setAgent(?Agent $agent): self
    {
        $this->agent = $agent;

        return $this;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
padlyuck, 2018-10-02
@padlyuck

why do you have an intermediate table in a separate entity? you need https://www.doctrine-project.org/projects/doctrine... as it seems to me, and the doctrine itself will complete the third tablet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question