getRepository(Post::class); /** @var array $posts */ $posts = $postRepository->findAll(); for ($i = 0; $i < $this->count; $i++) { $comment = new Comment( $this->faker->userName(), $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $this->faker->randomElement($posts), ); $manager->persist($comment); } $manager->flush(); } public function getDependencies(): array { return [ PostFixture::class, ]; } }