How to embed a link in a doctrine

I have 3 properties: User, Page,Post

In the object Post:

class Post
{
    /**
     * @ORM\ManyToOne(targetEntity="Page")
     */
    private $page;

    /**
     * @var ArrayCollection $subscribers Specify users that see this post.
     *
     * @ORM\ManyToMany(targetEntity="User", inversedBy="wallPosts")
     */
    private $subscribers;
}

In Pageenity:

class Page
{
    /**
     * @ORM\ManyToMany(targetEntity="User")
     */
    private $members;
}

When a publication is published, I want all user members to Page be installed as subscribers fromPost

$post->setSubscribers($post->getPage()->getMembers())

note : there Pagemay be several thousand users, what's the best way to get better performance? Should I use my own query, database triggers, or procedures?

+4
source share
1 answer

. 50 . . -

$page = $post->getPage();
for ($i = 1;; ++$i) {
  $members = $page->getPagindatedMembers($i);
  if (empty($members)) {
     break;
  }
  foreach ($members as $member) {
     $post->addSubscriber($member);
  }
  $em->flush();
  $em->clear(Member::class);
}
+1

Source: https://habr.com/ru/post/1613603/


All Articles