Skip to content

Instantly share code, notes, and snippets.

@RepComm
Created February 4, 2024 00:02
Show Gist options
  • Save RepComm/1c4ee0eb7c42a0d5bb3a37ce93fec70e to your computer and use it in GitHub Desktop.
Save RepComm/1c4ee0eb7c42a0d5bb3a37ce93fec70e to your computer and use it in GitHub Desktop.
pocketbase auto-append to container from created item.container reference
onModelBeforeCreate((e)=>{
const item_name = "responses";
const container_name = "tickets";
const container_ref = "ticket";
const container_id = e.model.get(container_ref);
if (container_id) {
const container = $app.dao().findRecordById(container_name, container_id);
const items = container.get(item_name);
const item_id = e.model.getId();
const items_updated = [...items, item_id];
container.set(item_name, items_updated);
$app.dao().saveRecord(container);
} else {
console.warn(container_id);
}
}, "responses");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment