PhoenixKit.Modules.Posts.PostMedia (phoenix_kit v1.7.62)

Copy Markdown View Source

Junction schema for post media attachments.

Links posts to uploaded files (images/videos) with ordering and captions. Enables ordered image galleries in posts with per-image captions.

Fields

  • post_uuid - Reference to the post
  • file_uuid - Reference to the uploaded file (PhoenixKit.Storage.File)
  • position - Display order (1, 2, 3, etc.)
  • caption - Optional caption/alt text for the image

Examples

# First image in post
%PostMedia{
  post_uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
  file_uuid: "018e3c4a-1234-5678-abcd-ef1234567890",
  position: 1,
  caption: "Beautiful sunset at the beach"
}

# Second image
%PostMedia{
  post_uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
  file_uuid: "018e3c4a-5678-1234-abcd-ef1234567890",
  position: 2,
  caption: nil
}

Summary

Functions

Changeset for creating or updating post media.

Types

t()

@type t() :: %PhoenixKit.Modules.Posts.PostMedia{
  __meta__: term(),
  caption: String.t() | nil,
  file: PhoenixKit.Modules.Storage.File.t() | Ecto.Association.NotLoaded.t(),
  file_uuid: UUIDv7.t(),
  inserted_at: DateTime.t() | nil,
  position: integer(),
  post: PhoenixKit.Modules.Posts.Post.t() | Ecto.Association.NotLoaded.t(),
  post_uuid: UUIDv7.t(),
  updated_at: DateTime.t() | nil,
  uuid: UUIDv7.t() | nil
}

Functions

changeset(media, attrs)

Changeset for creating or updating post media.

Required Fields

  • post_uuid - Reference to post
  • file_uuid - Reference to file
  • position - Display order (must be positive)

Validation Rules

  • Position must be greater than 0
  • Unique constraint on (post_uuid, position) - enforced at database level