Guest User

Untitled

a guest
Nov 24th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. $batchSize = 100; //Entity Manager will flush every batchSize times
  2. $i = 0;
  3.  
  4. foreach ($aTagCollection as $oTag) {
  5. $aMapping = $oTag->getMapping();
  6.  
  7. foreach ($aMapping as $oMapping) {
  8.  
  9. }
  10.  
  11. if (($i % $batchSize) === 0) {
  12. $this->em->flush(); //Execute all updates every 100 times
  13. $this->em->clear(); //Detaches all objects from Doctrine
  14. }
  15.  
  16. $i++;
  17. }
  18.  
  19. $this->em->flush();
  20.  
  21. /** @ORMOneToMany(targetEntity="Mapping",
  22. mappedBy="customerLabel", fetch="EXTRA_LAZY",
  23. cascade={"persist"}, orphanRemoval=true)
  24. */
  25. private $mapping;
  26.  
  27.  
  28. public function __construct()
  29. {
  30. $this->mapping = new ArrayCollection();
  31. }
  32.  
  33.  
  34. public function addMapping(Mapping $mapping)
  35. {
  36. $this->mapping[] = $mapping;
  37.  
  38. return $this;
  39. }
  40.  
  41.  
  42. public function removeMapping(Mapping $mapping)
  43. {
  44. $this->mapping->removeElement($mapping);
  45. }
  46.  
  47.  
  48. public function getMapping()
  49. {
  50. return $this->mapping;
  51. }
  52.  
  53. /**
  54. * @ORMManyToOne(targetEntity="Tag", inversedBy="mapping", cascade={"persist"})
  55. * @ORMJoinColumn(name="tag_id", referencedColumnName="id", onDelete="CASCADE")
  56. */
  57. private $tag;
  58.  
  59. public function setTag(Tag $tag = null)
  60. {
  61. $this->tag= $tag;
  62.  
  63. return $this;
  64. }
  65.  
  66. public function getTag()
  67. {
  68. return $this->tag;
  69. }
Add Comment
Please, Sign In to add comment