summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Mapping/AssociationOverride.php
blob: e0ebc073fd35a8195785c1f7255ee87d3e26c776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping;

/** This attribute is used to override association mapping of property for an entity relationship. */
final class AssociationOverride implements MappingAttribute
{
    /**
     * The join column that is being mapped to the persistent attribute.
     *
     * @var array<JoinColumn>|null
     */
    public readonly array|null $joinColumns;

    /**
     * The join column that is being mapped to the persistent attribute.
     *
     * @var array<JoinColumn>|null
     */
    public readonly array|null $inverseJoinColumns;

    /**
     * @param string                       $name               The name of the relationship property whose mapping is being overridden.
     * @param JoinColumn|array<JoinColumn> $joinColumns
     * @param JoinColumn|array<JoinColumn> $inverseJoinColumns
     * @param JoinTable|null               $joinTable          The join table that maps the relationship.
     * @param string|null                  $inversedBy         The name of the association-field on the inverse-side.
     * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY'|null $fetch
     */
    public function __construct(
        public readonly string $name,
        array|JoinColumn|null $joinColumns = null,
        array|JoinColumn|null $inverseJoinColumns = null,
        public readonly JoinTable|null $joinTable = null,
        public readonly string|null $inversedBy = null,
        public readonly string|null $fetch = null,
    ) {
        if ($joinColumns instanceof JoinColumn) {
            $joinColumns = [$joinColumns];
        }

        if ($inverseJoinColumns instanceof JoinColumn) {
            $inverseJoinColumns = [$inverseJoinColumns];
        }

        $this->joinColumns        = $joinColumns;
        $this->inverseJoinColumns = $inverseJoinColumns;
    }
}