Entities 0.2.2: Records can have a parent record
Entities 0.2.2 lets a record sit under another record of the same entity, so an entity’s records can form a tree, such as categories and their sub-categories.
The record form has a new Parent dropdown. It lists the entity’s other records, leaves out the record itself and everything under it, and starts with “— None (top level) —”. A choice that would create a loop is refused, with the error shown next to the field. The data navigator shows records in tree order, indented by depth, when it lists one entity without a status filter or search. A record that still has child records cannot be deleted forever until its children are moved or deleted.
Two redirect checks are also tighter. The public form no longer fails with a server error when the referring page is a protocol-relative address such as //evil.com/foo. The entity form’s “and Return” button only goes back to real admin pages, not lookalikes such as /admin-tools/foo.
Full release notes: Entities 0.2.2
0.2.2 · 12 May 2026
Added
PhoenixKitEntities.EntityData.tree_from_rows/1anddescendant_uuids_from_rows/2— list-accepting variants oflist_tree/2anddescendant_uuids/3. Callers that need both shapes from one entity load (e.g. the parent picker) can now fetch rows once and feed both helpers instead of paying for the samelist_by_entity/2call twice.- Pinning test for the bulk-restore default-status contract — a row trashed via
bulk_trash/2(no per-row metadata stash) restores to"draft", not"published". Guards against a future refactor accidentally re-publishing archived rows through the bulk path.
Fixed
entity_form_controller.exsafe_referer_path/2now explicitly rejects protocol-relative paths (//evil.com/foo). The same-host check already kept it from being an open redirect, but the rawpathwould bubble up toPhoenix.Controller.redirect(to: …)and trip its ownArgumentErrorguard with a 500. The fallback to"/"is now graceful. Same pass deduplicated the doubleURI.parse(referer)call by bindingqueryin the URI match.web/entity_form.exinternal_admin_path?/1now requires/admin/(with trailing slash) and explicitly rejects//-prefixed paths. PreviouslyString.contains?(path, "/admin")would also accept lookalikes like/admin-tools/fooand/x/admin.jsonas valid “and Return” targets.web/data_form.exparent picker no longer loads the entity’s row set twice — the previous call sequence toEntityData.list_tree/2followed byEntityData.descendant_uuids/3issued two fulllist_by_entity/2queries per mount. Now loads once and feeds both helpers.
Changed
web/data_navigator.exmaybe_tree_order/4delegates toEntityData.tree_from_rows/1instead of a near-duplicate localtree_order/1+walk_for_navigator/3implementation. Same defensive root-promotion behaviour, just from the shared source.- Inline comment on
EntityData.validate_parent_not_descendant/1documenting the validation-time race window (two concurrent edits on the same chain in opposite directions can each pass their own validator pass and then both commit, producing a cycle the DB will accept). Two fix paths sketched for a future PR —pg_advisory_xact_lock+ per-rowFOR UPDATEin the same txn, or a PostgresBEFORE INSERT/UPDATEtrigger with a recursive-CTE acyclicity check (lives in the companion migration repo).
Spec corrections
PhoenixKitEntities.get_mirror_settings/1— spec claimed%{definitions: boolean(), data: boolean()}but the impl returns%{mirror_definitions: …, mirror_data: …}. Spec aligned with impl + docstring example.PhoenixKitEntities.{enable,disable}_all_{definitions,data}_mirror/0— four specs claimed{non_neg_integer(), nil}but the impl returns{:ok, non_neg_integer()}. Every caller already pattern-matches{:ok, count}. Specs corrected.
Entities 0.2.2. Install or update: {:phoenix_kit_entities, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.