A
A
awda2dea2022-03-07 09:05:35
symfony
awda2dea, 2022-03-07 09:05:35

How to create dependencies of external tables with a SQL query through a repository?

PointsController.php on line 150:
App\Entity\PointsCities {#709 ▼
  -id: "1"
  -city: "City #1"
  -region_id: "2"
  -type: 1
}

Let's say there is a repository that, when requested by findAll, returns a certain collection of objects of the PointsController class. But! The returned entities contain only indexes (FKeys) to other tables from which it is necessary to pull up, for example) varchar string values. Of course, I can write an SQL query using QB, however .. then the returned result will be of type array, and I will have to iterate over the entire array, while also filling in the vector from PointsController entities, which I don’t see the point. Writing additional queries to retrieve data from related tables is another +2 SQL extra queries, in general, sheer absurdity. In fact, with one query, you need to pull out the data of adjacent tables for region_id and type, which in these tables have specific names of the varchar type ..

The body of the entity looks something like this
class PointsCities
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="bigint", options={"unsigned" : true})
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=50)
     */
    private $city;

    /**
     * @ORM\Column(type="bigint", nullable=true, options={"unsigned" : true})
     * @ORM\ManyToOne(targetEntity="PointsRegions")
     * @ORM\JoinColumn(name="region_id", referencedColumnName="id")
     */
    private $region_id;

    /**
     * @ORM\Column(type="smallint", options={"unsigned" : true})
     * @ORM\OneToOne(targetEntity="PointsCityTypes")
     */
    private $type;

    ........
}


The database model looks like this
6225a06c3b7a0142679254.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Kaznov, 2022-04-04
@Malverdo

in essence, you need to create an ArrayCollection
one-to-many
variable names should be CamelCase, instead of $region_id you need $regions
about Join doctrina works on pattern proxy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question