title: sqlalchemy how to generate (many-to-many) relationships with automap_base
body: <p>As a background: I'm creating an ORM based on a schema of an already existing database. - This due to the fact that the python application won't be the "owner" of said database.</p>
  
  <p>Now in this database there is a table called "<code>task</code>" and a table called "<code>task_notBefore__task_relatedTasks</code>" - this latter is a many-to-many relation between different entries in the "<code>task</code>" table.</p>
  
  <p>now <code>automap_base()</code> has an automated detection of these relationships as described <a href="http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html#many-to-many-relationships" rel="noreferrer">here</a>. However this fails for my case, and no relationship is being build.</p>
  
  <p>I then try to manually create the relationship:</p>
  
  <pre><code>from sqlalchemy.ext.automap import automap_base
  from sqlalchemy.ext.automap import generate_relationship
  from sqlalchemy.orm import sessionmaker, interfaces, relationship
  from sqlalchemy import create_engine
  
  class DBConnection:
      def __init__(self, connection_url, **kwargs):
          self.engine = create_engine(connection_url, **kwargs)
          self._Base = automap_base()
  
          self._Base.prepare(self.engine, reflect=True)
  
          self.Task = self._Base.classes.task
          self.Order = self._Base.classes.order
          self.Poller = self._Base.classes.poller
  
          rel = generate_relationship(self._Base, interfaces.MANYTOMANY, relationship, 'related', self.Task, self.Task,
                                      secondary=self._Base.classes.task_notBefore__task_relatedTasks, backref='notBefore')
  
          self._Session = sessionmaker()
          self._Session.configure(bind=self.engine)
  
          self.session = self._Session()
  </code></pre>
  
  <p>However this still doesn't "do" anything: it doesn't add anything to the <code>self.Task</code> "class".</p>
  
  <p>How would one do this?</p>