# `PhoenixKitComments.CommentMedia`
[🔗](https://github.com/BeamLabEU/phoenix_kit_comments/blob/v0.4.5/lib/phoenix_kit_comments/schemas/comment_media.ex#L1)

Junction schema linking a comment to an uploaded file.

Mirrors `PhoenixKitPosts.PostMedia` — each row attaches one
`PhoenixKit.Modules.Storage.File` to one `PhoenixKitComments.Comment`
with a stable `position` and an optional `caption`.

## Fields

- `comment_uuid` - The comment this media belongs to
- `file_uuid` - The `Storage.File` row (image / video / audio / document / other)
- `position` - 1-based display order within the comment's media list
- `caption` - Optional caption / alt text

## Constraints

- Unique `(comment_uuid, position)` so reordering can't collide
- `ON DELETE CASCADE` on `comment_uuid`: deleting a comment row also
  drops its media rows
- `ON DELETE RESTRICT` on `file_uuid`: a file may be referenced by
  other comments or posts, so the junction row is the only thing
  detaching removes; the file is reaped by the storage GC pass when no
  junction rows reference it.

# `t`

```elixir
@type t() :: %PhoenixKitComments.CommentMedia{
  __meta__: term(),
  caption: String.t() | nil,
  comment: PhoenixKitComments.Comment.t() | Ecto.Association.NotLoaded.t(),
  comment_uuid: UUIDv7.t(),
  file: PhoenixKit.Modules.Storage.File.t() | Ecto.Association.NotLoaded.t(),
  file_uuid: UUIDv7.t(),
  inserted_at: DateTime.t() | nil,
  position: integer(),
  updated_at: DateTime.t() | nil,
  uuid: UUIDv7.t() | nil
}
```

# `changeset`

Changeset for creating or updating a comment-media link.

Position is required and must be positive. Uniqueness on
`(comment_uuid, position)` is enforced at the DB level.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
