title: How to use joinedload/contains_eager for query-enabled relationships (lazy='dynamic' option) in SQLAlchemy
body: <p>I have the following model classes declared by SQLAlchemy:</p>
  
  <pre><code>class User(Base):
      id = Column(Integer, primary_key=True)
      name = Column(String, nullable=False, unique=True)
      created_at = Colmn(DateTime, nullable=False, default=func.now())
  
  class Post(Base):
      id = Column(Integer, primary_key=True)
      user_id = Column(Integer, ForeignKey(User.id), nullable=False)
      user = relationship(User, backref=backref('posts', lazy='dynamic'))
      title = Column(String, nullable=False)
      body = Column(Text, nullable=False)
      created_at = Colmn(DateTime, nullable=False, default=func.now())
  </code></pre>
  
  <p>As I quoted, these models have a relationship and its backref named <code>posts</code> set to be query-enabled (through <code>lazy='dynamic'</code> option). Because some users may have the large set of posts while most users don’t.</p>
  
  <p>With these models, I tried <code>joinedload</code> for <code>User.posts</code>, but I faced the error:</p>
  
  <pre><code>&gt;&gt;&gt; users = session.query(User).options(joinedload(User.posts))[:30]
  Traceback (most recent call last):
    ...
  InvalidRequestError: 'User.posts' does not support object population - eager loading cannot be applied.
  </code></pre>
  
  <p>Is there any way to work around this situation? I need following two functionalities both:</p>
  
  <ul>
  <li>Sometimes <code>User.posts</code> can be sliced to avoid eagerloading of the large set of posts written by heavy users.</li>
  <li>However usually <code>User.posts</code> should don’t produce 1+N queries.</li>
  </ul>