title: SQLAlchemy - order_by on relationship for join table
body: <p>I'm using declarative SQLAlchemy and I have three models:  <code>Role</code>, <code>Permission</code>, and <code>RolePermission</code>.  In my <code>Role</code> model, I have the following:</p>
  
  <pre><code>class Role(Base):
      name = Column(u'NAME', VARCHAR(50), nullable=False, unique=True)
      permissionLinks = relationship(RolePermission, backref="role", order_by=name)
      permissions = relationship(Permission, backref=backref("roles",
        order_by=name), secondary=RolePermission.__table__,
        order_by=Permission.name)
  </code></pre>
  
  <p>Now the <code>permissions</code> declaration works fine, and the permissions associated with a role come out sorted as I expect (by name).  However, <code>permissionLinks</code> fails with the following error:</p>
  
  <blockquote>
    <p>sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]The multi-part identifier "ROLES.NAME" could not be bound. (4104) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)') u'SELECT [ROLES_PERMISSIONS].[ROLE_ID] AS [ROLES_PERMISSIONS_ROLE_ID], [ROLES_PERMISSIONS].[PERMISSION_ID] AS [ROLES_PERMISSIONS_PERMISSION_ID], [ROLES_PERMISSIONS].[IS_DENIED] AS [ROLES_PERMISSIONS_IS_DENIED] \nFROM [ROLES_PERMISSIONS] \nWHERE [ROLES_PERMISSIONS].[ROLE_ID] = ? ORDER BY [ROLES].[NAME]' (19,)</p>
  </blockquote>
  
  <p>The problem is that <code>Role</code> is not being joined, so it can't sort by <code>Role.name</code>.  I tried specifying <code>primaryjoin=id == RolePermission.id1</code>, but that didn't seem to change anything.  How can I specify a join on this relationship such that I can sort by a field in one of the joined tables (namely, <code>Role.name</code>)?</p>