Plato.Content (plato v0.0.24)

Copy Markdown View Source

Content schema representing content instances.

Content stores field values as a JSONB map keyed by field IDs. Each content instance belongs to a schema and contains field data according to that schema's field definitions.

This module is primarily used internally by Plato. Use the Plato module for content queries and management instead.

Internal Structure

Content is stored with:

  • schema_id - Reference to the schema this content belongs to
  • field_values - Map of field_id => value pairs stored as JSONB

Field values are stored with string keys (field IDs) and can contain:

  • Simple strings for text fields
  • Maps for image fields (with url, storage_path, etc.)
  • Integer IDs for reference fields (resolved by ContentResolver)

Example Field Values

%{
  "1" => "Blog Post Title",
  "2" => "This is the post body...",
  "3" => 42,  # Author ID (reference field)
  "4" => %{    # Image field
    "url" => "...",
    "storage_path" => "...",
    "filename" => "..."
  }
}

Summary

Types

t()

@type t() :: %Plato.Content{
  __meta__: term(),
  field_values: map(),
  id: integer() | nil,
  inserted_at: DateTime.t() | nil,
  schema: term(),
  schema_id: integer(),
  updated_at: DateTime.t() | nil
}

Functions

changeset(content, attrs)

Creates a changeset for content.

create(attrs, repo \\ Plato.Repo)

@spec create(map(), module()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}