PhoenixKit.Modules.Comments.Comment (phoenix_kit v1.7.62)

Copy Markdown View Source

Schema for polymorphic comments with unlimited threading depth.

Supports nested comment threads (Reddit-style) with self-referencing parent/child relationships. Can be attached to any resource type via resource_type + resource_uuid.

Comment Status

  • published - Comment is visible
  • hidden - Comment is hidden by moderator
  • deleted - Comment deleted (soft delete)
  • pending - Awaiting moderation approval

Fields

  • resource_type - Type of resource (e.g., "post", "entity", "ticket")
  • resource_uuid - UUID of the resource
  • user_uuid - Reference to the commenter
  • parent_uuid - Reference to parent comment (nil for top-level)
  • content - Comment text
  • status - published/hidden/deleted/pending
  • depth - Nesting level (0=top, 1=reply, 2=reply-to-reply, etc.)
  • like_count - Denormalized like counter
  • dislike_count - Denormalized dislike counter

Summary

Functions

Changeset for creating or updating a comment.

Check if comment is deleted.

Check if comment is published.

Check if comment is a reply (has parent).

Check if comment is top-level (no parent).

Types

t()

@type t() :: %PhoenixKit.Modules.Comments.Comment{
  __meta__: term(),
  children: [t()] | Ecto.Association.NotLoaded.t(),
  content: String.t(),
  depth: integer(),
  dislike_count: integer(),
  inserted_at: DateTime.t() | nil,
  like_count: integer(),
  parent: t() | Ecto.Association.NotLoaded.t() | nil,
  parent_uuid: UUIDv7.t() | nil,
  resource_type: String.t(),
  resource_uuid: Ecto.UUID.t(),
  status: String.t(),
  updated_at: DateTime.t() | nil,
  user: PhoenixKit.Users.Auth.User.t() | Ecto.Association.NotLoaded.t() | nil,
  user_uuid: UUIDv7.t() | nil,
  uuid: UUIDv7.t() | nil
}

Functions

changeset(comment, attrs)

Changeset for creating or updating a comment.

Required Fields

  • resource_type - Type of resource being commented on
  • resource_uuid - UUID of the resource
  • user_uuid - Reference to commenter
  • content - Comment text

deleted?(arg1)

Check if comment is deleted.

published?(arg1)

Check if comment is published.

reply?(comment)

Check if comment is a reply (has parent).

top_level?(comment)

Check if comment is top-level (no parent).