|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
// phpcs:disable |
|
3
|
|
|
namespace TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasTemplateEntities; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Inflector\Inflector; |
|
6
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
|
7
|
|
|
use TemplateNamespace\Entities\TemplateEntity as TemplateEntity; |
|
8
|
|
|
use TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasTemplateEntitiesAbstract; |
|
9
|
|
|
use TemplateNamespace\Entity\Relations\TemplateEntity\Traits\ReciprocatesTemplateEntity; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Trait HasTemplateEntitiesOwningManyToMany |
|
13
|
|
|
* |
|
14
|
|
|
* The owning side of a Many to Many relationship between the Current Entity |
|
15
|
|
|
* and TemplateEntity |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association |
|
18
|
|
|
* |
|
19
|
|
|
* @package TemplateNamespace\Entity\Relations\TemplateEntity\Traits\HasTemplateEntities |
|
20
|
|
|
*/ |
|
21
|
|
|
// phpcs:enable |
|
22
|
|
|
trait HasTemplateEntitiesOwningManyToMany |
|
23
|
|
|
{ |
|
24
|
|
|
use HasTemplateEntitiesAbstract; |
|
25
|
|
|
|
|
26
|
|
|
use ReciprocatesTemplateEntity; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param ClassMetadataBuilder $builder |
|
30
|
|
|
* |
|
31
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
32
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function metaForTemplateEntities( |
|
35
|
|
|
ClassMetadataBuilder $builder |
|
36
|
|
|
): void { |
|
37
|
|
|
|
|
38
|
|
|
$manyToManyBuilder = $builder->createManyToMany( |
|
39
|
|
|
TemplateEntity::getPlural(), TemplateEntity::class |
|
40
|
|
|
); |
|
41
|
|
|
$manyToManyBuilder->inversedBy(static::getPlural()); |
|
42
|
|
|
$fromTableName = Inflector::tableize(static::getPlural()); |
|
43
|
|
|
$toTableName = Inflector::tableize(TemplateEntity::getPlural()); |
|
44
|
|
|
$manyToManyBuilder->setJoinTable($fromTableName.'_to_'.$toTableName); |
|
45
|
|
|
$manyToManyBuilder->addJoinColumn( |
|
46
|
|
|
static::getSingular().'_'.static::getIdField(), |
|
47
|
|
|
static::getIdField() |
|
48
|
|
|
); |
|
49
|
|
|
$manyToManyBuilder->addInverseJoinColumn( |
|
50
|
|
|
TemplateEntity::getSingular().'_'.TemplateEntity::getIdField(), |
|
51
|
|
|
TemplateEntity::getIdField() |
|
52
|
|
|
); |
|
53
|
|
|
$manyToManyBuilder->build(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|