简体   繁体   English

具有自定义 key_source 的数据联合依赖项

[英]Datajoint dependencies with custom key_source

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:例如,我的管道阶段都是参数化的,并使用 mixin key_source来指定给定数据集的每个阶段使用哪些参数:

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.因此,我失去了使用级联从自定义key_source中的非依赖表传播删除的能力——这在某些方面违反了数据完整性。 Also, when using dj.create_virtual_module, underlying functions like _jobs_to_do will not be correct.此外,当使用 dj.create_virtual_module 时, _jobs_to_do等底层函数将不正确。 Is there an alternate design that could allow me to keep these functionality?是否有替代设计可以让我保留这些功能?

That is correct.那是对的。

The foreign keys dictate how deletes are cascaded.外键决定了删除是如何级联的。 They also, by default define the key_source , ie the query that generates the values for the primary key values for automated computations.默认情况下,它们还定义key_source ,即为自动计算生成主键值的查询。 The default key_source query is the join of the tables referenced by foreign keys made from within the primary key of the computed table.默认的key_source查询是由计算表的主键中的外键引用的表的连接。 If you override the key_source to restrict the calculation to a specific subset, that will not affect the foreign key constraints.如果您覆盖key_source以将计算限制为特定子集,则不会影响外键约束。 So if you wish to alter how deletes are propagated perhaps the foreign key constraints need to be revised.因此,如果您希望更改删除的传播方式,则可能需要修改外键约束。

I know this is not necessarily helping your question directly, just highlighting the distinction of roles of foreign keys and key_source .我知道这不一定直接帮助您的问题,只是强调外键和key_source角色的区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM