Skip to content

New definition and syntax for subordinate relations. #146

@dimitri-yatsenko

Description

@dimitri-yatsenko

Today we discussed a clearer definition of subordinate relations. We propose the following definitions and syntax.

Base relation B is subordinate to base relation A when B is depends on A and A contains information that is inseparably tied to information in B so that A should never be populated without also populating B and B should never be deleted from without deleting matching tuples from A. A master relation can have multiple subordinate relations. We are not yet sure if nested subordinate relations make good sense.

A common case is a master-detail relationship when B contains a set of tuples for every tuple in A that form one inseparable group. These tuples can only be inserted or delete together as a complete group with their matching A tuple.

The subordinate relation always forms a primary dependency on the master relation.

According to the new definition, subordinate relation classes will be declared inside the master relation's class.

For example:

import datajoint as dj

schema = dj.schema(database='test', context=locals())

@schema
class Root(dj.Manual):
    definition = """  # root table from which all data are populated
    root_id :int 
    """

@schema 
class A(dj.Computed):
    definition = """  # master table
    -> Root
    """

    class B(dj.Subordinate):
        definition = """  # subordinate table
        -> A
        id_b :int 
        """

    def _make_tuples(self, key):
        self.insert1(key)
        sub = self.B()
        for b in range(10):
            sub.insert1(dict(key, id_b=b))

The schema decorator will now traverse the class and look for its properties of the type dj.Subordinate to find all subordinate tables. A subordinate relation will not have its own tier (manual, lookup, imported, or computed) and will need to subclass dj.Subordinate. Effectively, it has the same tier as its master. It's table name in MySQL will be formed by appending __class_name to its master's table name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions