Skip to main content

Module model

Module model 

Source
Expand description

Category models — real, migration-tracked tables (not a JSON blob). Two models:

  • Taxonomy (cms_taxonomy) — the vocabulary registry, mirroring cms_page_type: one row per registered vocabulary (category, countries, …), synced from handlers at seed.
  • Category (cms_category) — the abstract base row shared by every vocabulary: a materialized-path tree (like cms_page) with typed columns name / description / featured_image_id / thumbnail_id / parent_id, scoped to a taxonomy via taxonomy_id.

Custom vocabularies add extra typed fields in their own per-type extension table (unique category_id FK), exactly like a page type’s extension — see crate::category.

Parenting is cycle-guarded inside the move transaction (materialized- path prefix test) and build_tree is loop-safe (visited-set + depth cap), so a corrupted parent_id can never hang the process.

Structs§

Category
The abstract base category row — shared by every vocabulary, one row per term. Tree shape (path/depth/parent_id) mirrors crate::page::Page; extra per-vocabulary fields live in a per-type extension table keyed on id.
CategoryNode
A nested category for tree rendering — a row plus its (loop-safe) children.
NewCategory
A new category’s base fields (extension fields are saved separately by the handler, keyed on the returned id).
Taxonomy
A registered vocabulary. One row per taxonomy, synced from the TaxonomyHandler inventory at seed (upsert_taxonomy). Mirrors cms_page_type.

Enums§

CategoryError
Errors from category tree mutations. CycleAttempt mirrors crate::tree_ops::TreeError::CycleAttempt.

Constants§

DEFAULT_MAX_DEPTH
Default per-taxonomy nesting cap when a handler doesn’t set one. Also the backstop that limits damage from a corrupted tree.

Functions§

all_in_taxonomy
Every category in a taxonomy, ordered by path (tree pre-order).
build_tree
Build a nested CategoryNode tree from a flat, path-ordered row list. Loop-safe: groups by parent_id, materializes generation by generation with a visited-set + a hard depth cap (WALK_DEPTH_CAP). A corrupted parent_id cycle yields a truncated tree + a single tracing::error!, never an infinite loop / OOM.
children_of
Immediate children of parent (None = roots) within a taxonomy, ordered by sort_order then id.
create
Create a category. Validates parent (exists, same taxonomy, allowed by hierarchical, within max_depth) and slug-uniqueness, then inserts and materializes its path in one transaction.
delete
Delete a category. With children: reparent = true promotes them to the category’s own parent; otherwise the delete is rejected (CategoryError::HasChildren). Page↔category assignments are cleaned by crate::category::assign::delete_for_category_tx. Returns 1.
move_to
Re-parent a category (and its whole subtree) under new_parent (None = root). Cycle-guarded: the new parent may not be the category itself or any of its descendants. Enforces hierarchical + max_depth for the deepest moved node.
normalize_slug
Normalize a category slug like a page slug: lowercase, spaces/ underscores → hyphens, strip anything but [a-z0-9-], collapse repeats. Empty input falls back to category.
update
Update a category’s base fields in place (name/slug/description/media). Re-checks slug uniqueness among siblings (excluding self). Does not re-parent — use move_to for that.