Add attach/detach glue calls to calendar and market CRUD
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s

Wire up ContainerRelation tracking via attach_child/detach_child in:
- calendars: create (including revive), soft_delete
- markets: create (including revive), soft_delete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-14 09:52:13 +00:00
parent ee93832db0
commit fca0950cd1
2 changed files with 8 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from models.calendars import Calendar
from blog.models.ghost_content import Post # for FK existence checks
from glue.services.relationships import attach_child, detach_child
import unicodedata
import re
@@ -66,6 +67,7 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) ->
cal.deleted_at = utcnow()
await sess.flush()
await detach_child(sess, "page", cal.container_id, "calendar", cal.id)
return True
async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calendar:
@@ -98,12 +100,14 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
if existing.deleted_at is not None:
existing.deleted_at = None # revive
await sess.flush()
await attach_child(sess, "page", post_id, "calendar", existing.id)
return existing
raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.')
cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug)
sess.add(cal)
await sess.flush()
await attach_child(sess, "page", post_id, "calendar", cal.id)
return cal