SQLAlchemy ORM with dynamic table schema
<p>I am trying to task <strong>SQLAlchemy ORM</strong> to create class <code>Field</code> that describes all fields in my database:</p>

<pre><code>from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

class Field(Base):
    __tablename__ = 'fields'
    __table_args__ = {'schema':'SCM'}
    id = Column(String(20), primary_key=True)
</code></pre>

<p>The issue is that table <code>fields</code> describes different fields in different schemas, i.e. </p>

<pre><code>SCM.fields
TDN.fields
...
</code></pre>

<p>I need class Field to</p>

<ul>
<li>Be initialized with object <code>fieldset</code> before records can be read from db</li>
<li>Schema determined by <code>fieldset.get_schema()</code> before table <code>&lt;schema&gt;.fields</code> is read.</li>
</ul>

<p>Something like this:</p>

<p>session.query(Field(fieldset))).filter(Field.id=='some field')</p>

<p>However, adding </p>

<pre><code>def __init__(self, fieldset)
    pass
</code></pre>

<p>to <code>class Field</code> results in </p>

<blockquote>
  <p><code>__init__() takes 1 positional argument...</code></p>
</blockquote>

<ul>
<li>I could lump all <code>fields</code> tables into one schema and add column 'schema_name' but I still need Field have link to its fieldset.</li>
</ul>

<p>Can this be done using <strong>SQLAlchemy ORM</strong> or should I switch to <strong>SqlAlchemy Core</strong> where I would have more control over object instantiation?</p>