title: flask-sqlalchemy cross database with "dynamic" schema
body: <p>I'm attempting to use the "application factory" pattern from flask, but I seem to have a chicken-and-egg problem with my models. <a href="http://flask.pocoo.org/docs/patterns/appfactories/" rel="noreferrer">http://flask.pocoo.org/docs/patterns/appfactories/</a></p>
  
  <p>I am importing my views in the create_app function, which imports my models. So, I don't have a config in the app when my models are being defined. This is usually fine, using the bind keys, I can set up models to connect to different dbs.</p>
  
  <p>However, in this case, I have two sets of models, one from the default database, and another set on another db connection - and I'd like to cross-db join. I know that the usual method is to add</p>
  
  <pre><code>__table_args__ = { 'schema' : 'other_db_name' }
  </code></pre>
  
  <p>to my "other db" models.</p>
  
  <p>But...depending on the config, the 'other_db_name' may be different.</p>
  
  <p>So, now I have models being defined that require the schema name from the config, but with no schema from the config to put in the class definition. I also may simply be missing something in flask I wasn't aware of.</p>
  
  <p>(Side note - an easy fix for this is to configure Sqlalchemy to always output the schema name in the query, no matter what - but I can't seem to find a setting for this.)</p>
  
  <p>If anyone has any input on this, I'd be very much obliged. Thanks!</p>