G
G
gitdev2021-05-23 02:17:47
symfony
gitdev, 2021-05-23 02:17:47

How to get data from many to many fields in Symfony and how to implement it?

There are vacancies and for them I get data that is many to many with the help of another request and save it to the array of the current vacancy.

if ($vacancies) {
            $ids = array_column((array)$vacancies, 'id');
            foreach($vacancies as &$vacancy) {
                $vacancy['skills'] = $this->getRowsById($this->skillRepository->getSkillsByVacancyIds($ids), $vacancy['id']);
                $vacancy['cities'] = $this->getRowsById($this->cityRepository->getCitiesByVacancyIds($ids), $vacancy['id'], 'name_' . $GLOBALS['request']->getLocale());
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tukreb, 2021-05-23
@gitdev

First, do this
https://gist.github.com/Ocramius/3121916
Then, through the usual foreach, you access the necessary elements to the property with ManyToMany.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question