| @@ 70-98 (lines=29) @@ | ||
| 67 | * |
|
| 68 | * @param LoadClassMetadataEventArgs $eventArgs |
|
| 69 | */ |
|
| 70 | public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) |
|
| 71 | { |
|
| 72 | $metadata = $eventArgs->getClassMetadata(); |
|
| 73 | ||
| 74 | //set a relation between Page and User to define the page author |
|
| 75 | $metaBuilder = new ClassMetadataBuilder($metadata); |
|
| 76 | ||
| 77 | //Add author relation on view |
|
| 78 | if ($this->userClass && $metadata->name === 'Victoire\Bundle\BlogBundle\Entity\Article') { |
|
| 79 | $metadata->mapManyToOne([ |
|
| 80 | 'fieldName' => 'author', |
|
| 81 | 'targetEntity' => $this->userClass, |
|
| 82 | 'cascade' => ['persist'], |
|
| 83 | 'inversedBy' => 'articles', |
|
| 84 | 'joinColumns' => [ |
|
| 85 | [ |
|
| 86 | 'name' => 'author_id', |
|
| 87 | 'referencedColumnName' => 'id', |
|
| 88 | 'onDelete' => 'SET NULL', |
|
| 89 | ], |
|
| 90 | ], |
|
| 91 | ]); |
|
| 92 | } |
|
| 93 | ||
| 94 | // if $article's property exists, add the inversed side on User |
|
| 95 | if ($metadata->name === $this->userClass && property_exists($this->userClass, 'articles')) { |
|
| 96 | $metaBuilder->addOneToMany('articles', 'Victoire\Bundle\BlogBundle\Entity\Article', 'author'); |
|
| 97 | } |
|
| 98 | } |
|
| 99 | } |
|
| 100 | ||
| @@ 108-136 (lines=29) @@ | ||
| 105 | * |
|
| 106 | * @param LoadClassMetadataEventArgs $eventArgs |
|
| 107 | */ |
|
| 108 | public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) |
|
| 109 | { |
|
| 110 | $metadata = $eventArgs->getClassMetadata(); |
|
| 111 | ||
| 112 | //set a relation between Page and User to define the page author |
|
| 113 | $metaBuilder = new ClassMetadataBuilder($metadata); |
|
| 114 | ||
| 115 | //Add author relation on view |
|
| 116 | if ($this->userClass && $metadata->name === 'Victoire\Bundle\CoreBundle\Entity\View') { |
|
| 117 | $metadata->mapManyToOne([ |
|
| 118 | 'fieldName' => 'author', |
|
| 119 | 'targetEntity' => $this->userClass, |
|
| 120 | 'cascade' => ['persist'], |
|
| 121 | 'inversedBy' => 'pages', |
|
| 122 | 'joinColumns' => [ |
|
| 123 | [ |
|
| 124 | 'name' => 'author_id', |
|
| 125 | 'referencedColumnName' => 'id', |
|
| 126 | 'onDelete' => 'SET NULL', |
|
| 127 | ], |
|
| 128 | ], |
|
| 129 | ]); |
|
| 130 | } |
|
| 131 | ||
| 132 | // if $pages property exists, add the inversed side on User |
|
| 133 | if ($metadata->name === $this->userClass && property_exists($this->userClass, 'pages')) { |
|
| 134 | $metaBuilder->addOneToMany('pages', 'Victoire\Bundle\CoreBundle\Entity\View', 'author'); |
|
| 135 | } |
|
| 136 | } |
|
| 137 | ||
| 138 | /** |
|
| 139 | * If entity is a View |
|