'Determine the \'primaryjoin\' and \'secondaryjoin\' attributes,
if not passed to the constructor already.
This is based on analysis of the foreign key relationships
between the parent and target mapped selectables.'

def _determine_joins(self):

    if ((self.secondaryjoin is not None) and (self.secondary is None)):
        raise sa_exc.ArgumentError(('Property    %s    specified    with    secondary    join    condition    but    no    secondary    argument' % self.prop))
    try:
        consider_as_foreign_keys = (self.consider_as_foreign_keys or None)
        if (self.secondary is not None):
            if (self.secondaryjoin is None):
                self.secondaryjoin = join_condition(self.child_selectable, self.secondary, a_subset=self.child_local_selectable, consider_as_foreign_keys=consider_as_foreign_keys)
            if (self.primaryjoin is None):
                self.primaryjoin = join_condition(self.parent_selectable, self.secondary, a_subset=self.parent_local_selectable, consider_as_foreign_keys=consider_as_foreign_keys)
        elif (self.primaryjoin is None):
            self.primaryjoin = join_condition(self.parent_selectable, self.child_selectable, a_subset=self.parent_local_selectable, consider_as_foreign_keys=consider_as_foreign_keys)
    except sa_exc.NoForeignKeysError:
        if (self.secondary is not None):
            raise sa_exc.NoForeignKeysError(("Could    not    determine    join    condition    between    parent/child    tables    on    relationship    %s    -    there    are    no    foreign    keys    linking    these    tables    via    secondary    table    '%s'.        Ensure    that    referencing    columns    are    associated    with    a    ForeignKey    or    ForeignKeyConstraint,    or    specify    'primaryjoin'    and    'secondaryjoin'    expressions." % (self.prop, self.secondary)))
        else:
            raise sa_exc.NoForeignKeysError(("Could    not    determine    join    condition    between    parent/child    tables    on    relationship    %s    -    there    are    no    foreign    keys    linking    these    tables.        Ensure    that    referencing    columns    are    associated    with    a    ForeignKey    or    ForeignKeyConstraint,    or    specify    a    'primaryjoin'    expression." % self.prop))
    except sa_exc.AmbiguousForeignKeysError:
        if (self.secondary is not None):
            raise sa_exc.AmbiguousForeignKeysError(("Could    not    determine    join    condition    between    parent/child    tables    on    relationship    %s    -    there    are    multiple    foreign    key    paths    linking    the    tables    via    secondary    table    '%s'.        Specify    the    'foreign_keys'    argument,    providing    a    list    of    those    columns    which    should    be    counted    as    containing    a    foreign    key    reference    from    the    secondary    table    to    each    of    the    parent    and    child    tables." % (self.prop, self.secondary)))
        else:
            raise sa_exc.AmbiguousForeignKeysError(("Could    not    determine    join    condition    between    parent/child    tables    on    relationship    %s    -    there    are    multiple    foreign    key    paths    linking    the    tables.        Specify    the    'foreign_keys'    argument,    providing    a    list    of    those    columns    which    should    be    counted    as    containing    a    foreign    key    reference    to    the    parent    table." % self.prop))
