Answer the question
In order to leave comments, you need to log in
How to add a record to an intermediate table without creating a new object?
Can you please tell me how to add an entry to an intermediate table without creating a new object in Symfony?
There is this code:
$subscriber = $em->getRepository(Subscribers::class)->findOneBy(['id' => 1);
$subscriber->addBot($bot); // $bot - это сущность
$em->persist($subscriber);
$em->flush();
$findSubscriber = $em->getRepository(Subscribers::class)->findOneBy(['subscriber_id' => $subscriber['message']['from']['id']]);
if(!$findSubscriber) {
$subscribers = new Subscribers();
$subscribers->setUsername($subscriber['message']['from']['username']);
$subscribers->setSubscriberId($subscriber['message']['from']['id']);
$subscribers->addBot($bot);
$em->persist($subscribers);
$em->flush();
// здесь отрабатывает нормально
}
else {
foreach ($bot->getSubscribers()->toArray() as $botSubscriber) {
if ($botSubscriber->getSubscriberId() != $subscriber['message']['from']['id']) {
$findSubscriber->addBot($bot);
$em->persist($findSubscriber);
$em->flush();
// не отрабатывает
}
}
}
Answer the question
In order to leave comments, you need to log in
here it is necessary to look at the classes that are in the Entity. show me what's there?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question