-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostMeta.php
114 lines (105 loc) · 2.53 KB
/
PostMeta.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
declare(strict_types=1);
namespace ArrayAccess\TrayDigita\App\Modules\Posts\Entities;
use AllowDynamicProperties;
use ArrayAccess\TrayDigita\Database\Entities\Abstracts\AbstractBasedMeta;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Index;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
#[AllowDynamicProperties] #[Entity]
#[Table(
name: self::TABLE_NAME,
options: [
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'comment' => 'Post metadata',
'priority' => 101,
'primaryKey' => [
'id',
'name'
]
]
)]
#[Index(
name: 'index_name',
columns: ['name']
)]
#[Index(
name: 'relation_post_meta_post_id_posts_id',
columns: ['post_id']
)]
#[HasLifecycleCallbacks]
/**
* @property-read int $post_id
* @property-read Post $post
*/
class PostMeta extends AbstractBasedMeta
{
public const TABLE_NAME = 'post_meta';
#[Id]
#[Column(
name: 'id',
type: Types::BIGINT,
length: 20,
updatable: false,
options: [
'unsigned' => true,
'comment' => 'Primary key composite identifier'
]
)]
protected int $id;
#[
JoinColumn(
name: 'post_id',
referencedColumnName: 'id',
nullable: false,
onDelete: 'CASCADE',
options: [
'relation_name' => 'relation_post_meta_post_id_posts_id',
'onUpdate' => 'CASCADE',
'onDelete' => 'CASCADE'
]
),
ManyToOne(
targetEntity: Post::class,
cascade: [
"persist",
"remove",
// "merge",
"detach"
],
fetch: 'EAGER'
)
]
protected Post $post;
/**
* Allow associations mapping
* @see jsonSerialize()
*
* @var bool
*/
protected bool $entityAllowAssociations = true;
public function getPostId(): int
{
return $this->post_id;
}
public function setPostId(int $post_id): void
{
$this->post_id = $post_id;
}
public function setPost(Post $post): void
{
$this->post = $post;
$this->setPostId($post->getId());
}
public function getPost(): Post
{
return $this->post;
}
}