admin管理员组文章数量:1122846
I am updating tbla."field_2"
from a trigger in tblb
. Except tbla."field_2"
is protected with a pgtrigger.ReadOnly
trigger.
This works without the pgtrigger.ReadOnly
trigger in TblA
. How would I do it and keep the pgtrigger.ReadOnly
trigger on TblA.field_2
?
Model TblA(models.Model):
field_1 = models.CharField(max_length=20)
field_2 = models.PositiveIntegerField(default=0)
class Meta:
triggers = [
pgtrigger.ReadOnly(
name='read_only_field_2',
fields=['field_2']
)
]
class TblB(models.Model):
field_a = models.ForeignKey(TblA, on_delete=models.SET_NULL)
class Meta:
pgtrigger.Trigger(
func=pgtrigger.Func('''
IF (NEW."{columns[field_a]}" IS NOT NULL) THEN
UPDATE "tbla"
SET "tbla"."field_2" = "tbla"."field_2" + 1
WHERE
"tbla"."id" = NEW.{columns[field_a]}
END IF;
RETURN NEW;
''')
),
when=pgtrigger.Before,
operation=pgtrigger.Insert,
name='increment_tbla_field_2'
),
I was thinking to mimic pgtrigger.ignore()
functionality within the trigger by using set_config
however I am not very familiar how persistent set_config
is.
Do I need to clean up at the end of the trigger? Is this doable?
set_config('pgtrigger.ignore', '{myapp:pgtrigger_read_only_field_2_c8215,pgtrigger_read_only_field_2_c8215}', true)
本文标签: postgresqlHow would you ignore a trigger within another trigger with djangopgtriggerStack Overflow
版权声明:本文标题:postgresql - How would you ignore a trigger within another trigger with django-pgtrigger - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300974a1931016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论