0

I use non-dependent tables to restrict using a custom key source. As an example, my pipeline stages are all parameterized and use a mixin key_source to specify which parameters are used for each stage for a given dataset:

class ParamsMixin:
    @property
    def key_source(self):
        return super().key_source & (models.Processing * models.Specification)

I have other examples that use a custom query to do a restriction:

    @property
    def key_source(self):
        # Only normalize combinatorial rounds.
        return (super().key_source * models.AcquisitionRound) & {
            "acquisition_round_kind": "combinatorial"
        }

This works great for data processing, but the dependencies are not explicit in the table definition. Therefore, I lose the ability to use cascades to propagate deletions from the non-dependent tables in the custom key_source -- which violates data integrity in some respects. Also, when using dj.create_virtual_module, underlying functions like _jobs_to_do will not be correct. Is there an alternate design that could allow me to keep these functionality?

4

1 回答 1

0

那是对的。

外键决定了删除是如何级联的。它们还默认定义key_source,即为自动计算生成主键值的查询。默认key_source查询是由计算表的主键中的外键引用的表的连接。如果您覆盖将key_source计算限制为特定子集,则不会影响外键约束。因此,如果您希望更改删除的传播方式,则可能需要修改外键约束。

我知道这不一定直接帮助你的问题,只是强调外键和key_source.

于 2022-01-08T21:40:57.193 回答