Answer the question
In order to leave comments, you need to log in
Querying data from a database in a loop with orm symfony behaves strangely, what am I missing?
The essence of the task is to output data from the database to the console in an endless loop.
To do this, I created a command:
class TestCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->container->get('doctrine')->getManager();
$repository = $doctrine->getRepository(MyClass::class);
while (true) {
$my_data = $repository->getFewData();
echo $my_data[0]->getMyField() . "\n";
sleep(2);
}
}
public function getFewData()
{
return $this->createQueryBuilder('c')
->where('c.id = 1')
->getQuery()
->getResult();
}
Answer the question
In order to leave comments, you need to log in
Solved the problem by inserting inside the loop: $doctrine->clear();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question