Expand description
Category models — real, migration-tracked tables (not a JSON blob). Two models:
Taxonomy(cms_taxonomy) — the vocabulary registry, mirroringcms_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 (likecms_page) with typed columnsname/description/featured_image_id/thumbnail_id/parent_id, scoped to a taxonomy viataxonomy_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) mirrorscrate::page::Page; extra per-vocabulary fields live in a per-type extension table keyed onid. - Category
Node - 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
TaxonomyHandlerinventory at seed (upsert_taxonomy). Mirrorscms_page_type.
Enums§
- Category
Error - Errors from category tree mutations.
CycleAttemptmirrorscrate::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
CategoryNodetree from a flat, path-ordered row list. Loop-safe: groups byparent_id, materializes generation by generation with a visited-set + a hard depth cap (WALK_DEPTH_CAP). A corruptedparent_idcycle yields a truncated tree + a singletracing::error!, never an infinite loop / OOM. - children_
of - Immediate children of
parent(None = roots) within a taxonomy, ordered bysort_orderthenid. - create
- Create a category. Validates parent (exists, same taxonomy, allowed by
hierarchical, withinmax_depth) and slug-uniqueness, then inserts and materializes itspathin one transaction. - delete
- Delete a category. With children:
reparent = truepromotes them to the category’s own parent; otherwise the delete is rejected (CategoryError::HasChildren). Page↔category assignments are cleaned bycrate::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. Enforceshierarchical+max_depthfor 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 tocategory. - 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_tofor that.