aboutsummaryrefslogtreecommitdiff
path: root/src/model/entities/NodeDataAsset.php
blob: 7f7008e8df6a430a000b5cd5972d96b92b9d7f67 (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
52
53
54
55
<?php
// src/model/entities/NodeDataAsset.php
//
// entité intermédiaire avec 3 colonnes

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: TABLE_PREFIX . 'nodedata_asset')]
#[ORM\UniqueConstraint(name: 'unique_role_per_node', columns: ['node_data_id', 'role'])] // un rôle UNIQUE pour chaque node_data_id, excellent!
class NodeDataAsset
{
    // clé primaire double
    // inconvénient: impossible d'utiliser deux fois la même paire node_data/asset, même pour des rôles différents
    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: NodeData::class, inversedBy: 'nda_collection')]
    #[ORM\JoinColumn(name: 'node_data_id', referencedColumnName: 'id_node_data', onDelete: 'CASCADE')]
    private NodeData $node_data;

    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Asset::class)]
    #[ORM\JoinColumn(name: 'asset_id', referencedColumnName: 'id_asset', onDelete: 'CASCADE')]
    private Asset $asset;

    #[ORM\Column(type: 'string', length: 50)]
    private string $role;

    public function __construct(NodeData $node_data, Asset $asset, string $role){
        $this->node_data = $node_data;
        $this->asset = $asset;
        $this->role = $role;
    }

    /*public function getNodeData(): NodeData
    {
        return $this->node_data;
    }*/
    public function getAsset(): Asset
    {
        return $this->asset;
    }
    public function setAsset(Asset $asset): self
    {
        $this->asset = $asset;
        return $this;
    }
    public function getRole(): string
    {
        return $this->role;
    }
}