From 6cd539d69775eda0c38abc371f68bf6b2181aa88 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Mon, 29 Jul 2019 14:06:57 +0200 Subject: [PATCH] feature #4: add relations to upsert_article --- resources/functions/article/upsert_article.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/functions/article/upsert_article.sql b/resources/functions/article/upsert_article.sql index 4c3090c..286f203 100644 --- a/resources/functions/article/upsert_article.sql +++ b/resources/functions/article/upsert_article.sql @@ -16,6 +16,15 @@ begin from json_populate_record(null::article, resource) returning id into new_id; + if resource->>'relations' is not null then + insert into article_relations (source_id, target_id, created_by_id) + select + (resource->>'id')::uuid, + id, + (resource#>>'{created_by, id}')::uuid + from json_populate_recordset(null::article, resource->>'relations'); + end if; + select find_article_by_id(new_id) into resource; end; $$;