title: SQLAlchemy Polymorphic Relationship with Concrete Inheritance
body: <p>I am using the concrete table inheritance with SQLAlchemy. In declartive style model class, I have configured it successfully.</p>
  
  <p>My code just like:</p>
  
  <pre><code>class Entry(AbstractConcreteBase, db.Model):
      """Base Class of Entry."""
  
      id = db.Column(db.Integer, primary_key=True, nullable=False)
      created = db.Column(db.DateTime, nullable=False)
      post_id = declared_attr(lambda c: db.Column(db.ForeignKey("post.id")))
      post = declared_attr(lambda c: db.relationship("Post", lazy="joined"))
  
      @declared_attr
      def __tablename__(cls):
          return cls.__name__.lower()
  
      @declared_attr
      def __mapper_args__(cls):
          # configurate subclasses about concrete table inheritance
          return {'polymorphic_identity': cls.__name__,
                  'concrete': True} if cls.__name__ != "Entry" else {}
  
  class TextEntry(Entry):
      """Text and Article Entry."""
  
      text = db.deferred(db.Column(db.Text, nullable=False))
  
  class PhotoEntry(Entry):
      """Photo Entry."""
  
      path = db.deferred(db.Column(db.String(256), nullable=False))
  </code></pre>
  
  <p>It works fine while testing it in the shell:</p>
  
  <pre><code>&gt;&gt;&gt; from models.entry import Entry
  &gt;&gt;&gt;
  &gt;&gt;&gt; Entry.query.all()
  [&lt;PhotoEntry 'Title' created by tonyseek&gt;,
   &lt;PhotoEntry 'TITLE 2' created by tonyseek&gt;,
   &lt;PhotoEntry 'Title 3' created by tonyseek&gt;,
   &lt;PhotoEntry 'Title 4' created by tonyseek&gt;,
   &lt;TextEntry 'Title' created by tonyseek&gt;]
  </code></pre>
  
  <p>Then I fall into trouble while setting the relationship in other models. Each entry has a foreign key <code>post_id</code> to join <code>Post</code> model, but I could not define the back reference in <code>Post</code>. That can't work:</p>
  
  <pre><code>class Post(db.Model):
      """An Post."""
  
      id = db.Column(db.Integer, primary_key=True, nullable=False)
      description = db.Column(db.Unicode(140), nullable=False)
      entries = db.relationship(Entry, lazy="dynamic")
  </code></pre>
  
  <p>It raised a Exception and said:</p>
  
  <blockquote>
    <p>InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers.  Original exception was: Class 'models.entry.Entry' is not mapped.</p>
  </blockquote>
  
  <p>Obvious the <code>Entry</code> is a abstract class, which couldn't be mapped to a real exist table. The document in official website has a example but its base class is not abstract. Now how should I do to set the polymorphic relationship with a abstract model?</p>