title: Sqlalchemy get data from relationship
body: <p>I have this models</p>
  
  <pre><code>class Post(Base):
      __tablename__ = 'posts'
      id = Column(Integer, primary_key=True)
      content = Column(Text)
      author = Column(Integer, ForeignKey('users.id'))
      to_topic = Column(Integer, ForeignKey('topics.id'))
  
      def __init__(self, content: str, author: int, to_topic: int) -&gt; None:
          self.content = content
          self.author = author
          self.to_topic = to_topic
  
  class User(Base):
      __tablename__ = "users"
      id = Column(Integer, primary_key=True)
      username = Column(String(30))
      email = Column(String(40))
      password = Column(String(255))
      registred_at = Column(DateTime, default=datetime.datetime.now)
      last_logged_in = Column(DateTime)
      last_login_attempt = Column(DateTime)
      avatar = Column(Integer, ForeignKey('files.id'))
      role = Column(String(20))
      email_confirm = Column(Boolean, default=False)
      children_forum = relationship('Forum')
      children_topic = relationship('Topic')
      children_post = relationship('Post')
  </code></pre>
  
  <p>And I am trying to get query that will contain Post.content, Post.author.username but how do i do this in sessions?</p>
  
  <p>I tried</p>
  
  <pre><code> posts = db_session.query(Post, User).filter(
          Post.to_topic == topic_id).with_entities(Post.content, Post.author.username)
  </code></pre>
  
  <p>but that doesnt work because author is just integer (id) so I expect that I need somehow get the author object and post object in one query, but I dont know how. In sql that would be easy just 2 queries but here I dont know how it´s done.</p>