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; $$;