'Determine if this relationship is one to many, many to one,
many to many.'

def _determine_direction(self):

    if (self.secondaryjoin is not None):
        self.direction = MANYTOMANY
    else:
        parentcols = util.column_set(self.parent_selectable.c)
        targetcols = util.column_set(self.child_selectable.c)
        onetomany_fk = targetcols.intersection(self.foreign_key_columns)
        manytoone_fk = parentcols.intersection(self.foreign_key_columns)
        if (onetomany_fk and manytoone_fk):
            self_equated = self.remote_columns.intersection(self.local_columns)
            onetomany_local = self.remote_columns.intersection(self.foreign_key_columns).difference(self_equated)
            manytoone_local = self.local_columns.intersection(self.foreign_key_columns).difference(self_equated)
            if (onetomany_local and (not manytoone_local)):
                self.direction = ONETOMANY
            elif (manytoone_local and (not onetomany_local)):
                self.direction = MANYTOONE
            else:
                raise sa_exc.ArgumentError(("Can't    determine    relationship    direction    for    relationship    '%s'    -    foreign    key    columns    within    the    join    condition    are    present    in    both    the    parent    and    the    child's    mapped    tables.        Ensure    that    only    those    columns    referring    to    a    parent    column    are    marked    as    foreign,    either    via    the    foreign()    annotation    or    via    the    foreign_keys    argument." % self.prop))
        elif onetomany_fk:
            self.direction = ONETOMANY
        elif manytoone_fk:
            self.direction = MANYTOONE
        else:
            raise sa_exc.ArgumentError(("Can't    determine    relationship    direction    for    relationship    '%s'    -    foreign    key    columns    are    present    in    neither    the    parent    nor    the    child's    mapped    tables" % self.prop))
