check-existing-on-create
All checks were successful
Deploy on push / deploy (push) Successful in 1m9s
All checks were successful
Deploy on push / deploy (push) Successful in 1m9s
This commit is contained in:
parent
ac9f1d8a40
commit
a25a434ea2
|
@ -133,13 +133,18 @@ async def create_shout(_, info, inp):
|
||||||
# NOTE: requesting new shout back
|
# NOTE: requesting new shout back
|
||||||
shout = session.query(Shout).where(Shout.slug == slug).first()
|
shout = session.query(Shout).where(Shout.slug == slug).first()
|
||||||
if shout:
|
if shout:
|
||||||
sa = ShoutAuthor(shout=shout.id, author=author_id)
|
# Проверка на существование записи
|
||||||
session.add(sa)
|
existing_sa = session.query(ShoutAuthor).filter_by(shout=shout.id, author=author_id).first()
|
||||||
|
if not existing_sa:
|
||||||
|
sa = ShoutAuthor(shout=shout.id, author=author_id)
|
||||||
|
session.add(sa)
|
||||||
|
|
||||||
topics = session.query(Topic).filter(Topic.slug.in_(inp.get("topics", []))).all()
|
topics = session.query(Topic).filter(Topic.slug.in_(inp.get("topics", []))).all()
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
t = ShoutTopic(topic=topic.id, shout=shout.id)
|
existing_st = session.query(ShoutTopic).filter_by(shout=shout.id, author=topic.id).first()
|
||||||
session.add(t)
|
if not existing_st:
|
||||||
|
t = ShoutTopic(topic=topic.id, shout=shout.id)
|
||||||
|
session.add(t)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user