From 556b8f8265f98a0f89019dc70dcf236e7923444e Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 18 Sep 2021 14:09:14 +0100 Subject: [PATCH] [ENTITY][NoteTag] Add 'canonical' field to tag --- src/Entity/NoteTag.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Entity/NoteTag.php b/src/Entity/NoteTag.php index c6fcdfed64..7834ceb31a 100644 --- a/src/Entity/NoteTag.php +++ b/src/Entity/NoteTag.php @@ -20,6 +20,7 @@ namespace App\Entity; use App\Core\Entity; +use Component\Tag\Tag; use DateTimeInterface; /** @@ -41,6 +42,7 @@ class NoteTag extends Entity // {{{ Autocode // @codeCoverageIgnoreStart private string $tag; + private string $canonical; private int $note_id; private \DateTimeInterface $created; @@ -55,6 +57,17 @@ class NoteTag extends Entity return $this->tag; } + public function setCanonical(string $canonical): self + { + $this->canonical = $canonical; + return $this; + } + + public function getCanonical(): string + { + return $this->canonical; + } + public function setNoteId(int $note_id): self { $this->note_id = $note_id; @@ -86,14 +99,16 @@ class NoteTag extends Entity 'name' => 'note_tag', 'description' => 'Hash tags on notes', 'fields' => [ - 'tag' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this note'], - 'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to tagged note'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'tag' => ['type' => 'varchar', 'length' => Tag::MAX_TAG_LENGTH, 'not null' => true, 'description' => 'hash tag associated with this note'], + 'canonical' => ['type' => 'varchar', 'length' => Tag::MAX_TAG_LENGTH, 'not null' => true, 'description' => 'ascii slug of hash tag'], + 'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to tagged note'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['tag', 'note_id'], 'indexes' => [ 'note_tag_created_idx' => ['created'], 'note_tag_note_id_idx' => ['note_id'], + 'note_tag_canonical_idx' => ['canonical'], 'note_tag_tag_created_note_id_idx' => ['tag', 'created', 'note_id'], ], ];