(self, referenced, dependent)
Add a link between two relations to the database. If either relation
        does not exist, it will be added as an "external" relation.

        The dependent model refers _to_ the referenced model. So, given
        arguments of (jake_test, bar, jake_test, foo):
        both values are in the schema jake_test and foo is a view that refers
        to bar, so "drop bar cascade" will drop foo and all of foo's
        dependents.

        :param BaseRelation referenced: The referenced model.
        :param BaseRelation dependent: The dependent model.
        :raises InternalError: If either entry does not exist.
Add a link between two relations to the database. If either relation
        does not exist, it will be added as an "external" relation.
Add a link between two relations to the database . If either relation does not exist it will be added as an external relation .
def add_link(self, referenced, dependent):
        """Add a link between two relations to the database. If either relation
        does not exist, it will be added as an "external" relation.

        The dependent model refers _to_ the referenced model. So, given
        arguments of (jake_test, bar, jake_test, foo):
        both values are in the schema jake_test and foo is a view that refers
        to bar, so "drop bar cascade" will drop foo and all of foo's
        dependents.

        :param BaseRelation referenced: The referenced model.
        :param BaseRelation dependent: The dependent model.
        :raises InternalError: If either entry does not exist.
        """
        ref_key = _make_key(referenced)
        if (ref_key.database, ref_key.schema) not in self:
            # if we have not cached the referenced schema at all, we must be
            # referring to a table outside our control. There's no need to make
            # a link - we will never drop the referenced relation during a run.
            fire_event(UncachedRelation(dep_key=dependent, ref_key=ref_key))
            return
        if ref_key not in self.relations:
            # Insert a dummy "external" relation.
            referenced = referenced.replace(
                type=referenced.External
            )
            self.add(referenced)

        dep_key = _make_key(dependent)
        if dep_key not in self.relations:
            # Insert a dummy "external" relation.
            dependent = dependent.replace(
                type=referenced.External
            )
            self.add(dependent)
        fire_event(AddLink(dep_key=dep_key, ref_key=ref_key))
        with self.lock:
            self._add_link(ref_key, dep_key)
def add_link ( self , referenced , dependent ) : ref_key = _make_key ( referenced ) if ( ref_key . database , ref_key . schema ) not in self : # if we have not cached the referenced schema at all, we must be # referring to a table outside our control. There's no need to make # a link - we will never drop the referenced relation during a run. fire_event ( UncachedRelation ( dep_key = dependent , ref_key = ref_key ) ) return if ref_key not in self . relations : # Insert a dummy "external" relation. referenced = referenced . replace ( type = referenced . External ) self . add ( referenced ) dep_key = _make_key ( dependent ) if dep_key not in self . relations : # Insert a dummy "external" relation. dependent = dependent . replace ( type = referenced . External ) self . add ( dependent ) fire_event ( AddLink ( dep_key = dep_key , ref_key = ref_key ) ) with self . lock : self . _add_link ( ref_key , dep_key )