title: Forcing inner join with many-to-many relationship in sqlalchemy
body: <p>I'm using declarative_base() and trying to figure out how to enforce a lazy inner join when using a many-to-many relationship.</p>
  
  <p>I have tables in MySQL and InnoDB with Foreign key constraints defined.</p>
  
  <pre><code>users: userid, name
  permissions: permissionid, name
  users_permissions: userid, permissionid</code></pre>
  
  <p>I'm using <code>metadata.reflect()</code> to load my database.</p>
  
  <pre><code>
  class User_Perm(Base):
      __table__ = Base.metadata.tables['users_permissions']
  
  class User(Base):
      __table__ = Base.metadata.tables['users']
  
      permissions = orm.relationship('Permission',
              secondary=User_Perm.__table__,
              order_by='Perm.name',
              innerjoin=True,
              lazy=True,
              )
  
  class Permission(Base):
      __table__ = Base.metadata.tables['permissions']
  </code></pre>
  
  <p>Whenever I select</p>
  
  <pre><code>u = Session().query(User).filter(User.name == 'myuser').first()
  u.permissions</code></pre>
  
  <p>The query received by MySQL server is:</p>
  
  <pre><code>SELECT permissions.permissionid AS permissions_permissionid,
       permissions.name AS permissions_name
  FROM permissions, users_permissions 
  WHERE ? = users_permissions.userid
      AND permissions.permissionid = users_permissions.permissionid
  ORDER BY permissions.name</code></pre>
  
  <p>As we can see, the <code>FROM permissions, users_permissions</code> is not an inner join. Can I force this without the need to use <code>lazy=False</code> because if I do so, the cascading effect will be to load too much information as <code>permissions</code> are also in relationship with another table (not mentioned in example) and <code>users</code> is also related to other tables (again, not mentioned in example). I would like to use the same template for relationship for all my classes.</p>
  
  <p>EDIT: <em>CONTEXT</em> I'm trying to replicate all the SQL queries to match those from the current system. I'm trying to migrate from <code>oursql</code> to <code>sqlalchemy orm</code>.</p>