Created
February 4, 2024 00:02
-
-
Save RepComm/1c4ee0eb7c42a0d5bb3a37ce93fec70e to your computer and use it in GitHub Desktop.
pocketbase auto-append to container from created item.container reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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