Skip to content

Latest commit

 

History

History
156 lines (114 loc) · 6.3 KB

File metadata and controls

156 lines (114 loc) · 6.3 KB
//////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT MODIFY THIS FILE                                                                  //
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
// Source: schema.zmodel · Generated: 2026-02-23                                            //
//////////////////////////////////////////////////////////////////////////////////////////////

Index / Models / Comment

🗃️ Comment Model

A threaded comment on an article.

Comments support one level of nesting via parentId. Top-level comments have parentId set to null. Replies are displayed in chronological order beneath their parent.

Soft-deletion is used so that reply threads remain coherent even after a parent comment is removed. Deleted comments display as "[deleted]" in the UI.

Category: Content · Since: 1.0 · Defined in: content.zmodel


Declaration · content.zmodel
model Comment with Timestamps, SoftDeletable {
    id          String    @id @default(cuid())
    body        String    @length(1, 5000)
    parent      Comment?  @relation("Replies", fields: [parentId], references: [id])
    parentId    String?
    replies     Comment[] @relation("Replies")
    author      User      @relation(fields: [authorId], references: [id])
    authorId    String
    article     Article   @relation(fields: [articleId], references: [id])
    articleId   String
    workspace   Workspace @relation(fields: [workspaceId], references: [id])
    workspaceId String

    @@allow('read', article.status == 'PUBLISHED' || workspace.members?[user == auth()])
    @@allow('create', workspace.members?[user == auth()])
    @@allow('update', author == auth() && deletedAt == null)
    @@deny('delete', true)
    @@index([articleId])
    @@index([authorId])
    @@meta('doc:category', 'Content')
    @@meta('doc:since', '1.0')
}

On this page: Mixins · Fields · Relationships · Access Policies · Indexes · Validation Rules

🧩 Mixins

Reusable field groups mixed into this model.

📋 Fields

All fields defined on this entity, including inherited fields from mixins and parent models.

Field Type Required Default Attributes Source Description
createdAt DateTime Yes now() Timestamps When the record was first created. Immutable after insert.
updatedAt DateTime Yes @updatedAt Timestamps When the record was last modified. Updated automatically.
deletedAt DateTime? No SoftDeletable When the record was soft-deleted, or null if active.
deletedBy String? No SoftDeletable The ID of the user who performed the deletion, for audit purposes.
id String Yes cuid() @id
body String Yes @length(1, 5000) Comment body in Markdown format. Supports inline formatting
and @mention syntax for notifying other users.
parent Comment? No @relation("Replies", fields: [parentId], references: [id]) Parent comment for threaded replies. Null for top-level comments.
parentId String? No
replies Comment[] No @relation("Replies") Replies to this comment.
author User Yes @relation(fields: [authorId], references: [id])
authorId String Yes
article Article Yes @relation(fields: [articleId], references: [id])
articleId String Yes
workspace Workspace Yes @relation(fields: [workspaceId], references: [id])
workspaceId String Yes

🔗 Relationships

Foreign key relationships to other models in the schema.

Field Related Model Type
article Article Many→One
author User Many→One
parent Comment Many→One?
replies Comment One→Many
workspace Workspace Many→One

diagram

🔐 Access Policies

ZenStack access control rules that determine who can read, create, update, or delete records.

Important

Operations are denied by default. @@allow rules grant access; @@deny rules override any allow.

Operation Rule Effect
read `article.status == 'PUBLISHED'
create workspace.members?[user == auth()] Allow
update author == auth() && deletedAt == null Allow
delete true Deny

📇 Indexes

Database indexes defined on this model for query performance.

Fields Type
[articleId] Index
[authorId] Index

✅ Validation Rules

Field-level and model-level validation constraints enforced at the ORM layer.

Field Rule
body @length

📚 References


Previous: Category · Next: Invoice