title: Flask-SQLAlchemy: Query only certain columns, return one-to-many relationships as lists
body: <p>How do I query only certain columns of a table AND return fields with one-to-many relationships as lists in flask-sqlalchemy?</p>
  
  <p>This is my models.py:</p>
  
  <pre><code>class Article(db.Model):
      __tablename__ = 'articles'
  
      id = db.Column(db.Integer, primary_key=True)
      title = db.Column(db.String(255))
      full_text = db.Column(db.Text)
      authors = relationship('Person',
              secondary=AssArtPer,
              backref='articles'
              )
  
  class Person(db.Model):
      __tablename__ = 'persons'
      id = db.Column(db.Integer, primary_key=True)
      full_name = db.Column(db.String(255))
  
  
  AssArtPer = db.Table('ass_articles_persons',
      db.Column('art_id', db.Integer, db.ForeignKey('articles.id')),
      db.Column('per_id', db.Integer, db.ForeignKey('persons.id'))
      )
  </code></pre>
  
  <p>When I do</p>
  
  <pre><code>results = Article.query.all()
  </code></pre>
  
  <p>EDIT: I am then passing the <code>results</code> to a jinja2 template which is handing it over to a macro:</p>
  
  <pre><code>{% for r in results %}
      {% macros.render_article(r) %}
  {% endfor %}
  
  {% macro render_article(result) %}
      {% for a in result.authors %}
          ...render something
      {% endfor %}
  {% endmacro %}
  </code></pre>
  
  <p>Now, I would like to limit the original query to exclude the Article.full_text column because it takes very long and I can load the full text with an ajax call later. I know that I can specify certain columns to be queried with:</p>
  
  <pre><code>results = Article.query.with_entities(
      Article.id,
      Article.title,
      Article.authors
      ).all()
  </code></pre>
  
  <p>BUT this doesn't work. The query doesn't return anything and doesn't throw an error either.</p>
  
  <p>I tried a join like so:</p>
  
  <pre><code>results = Article.query.join(Article.authors).with_entities(Person.id, Person.full_name)
  </code></pre>
  
  <p>...which is working fine, but I can not specify any other columns then. </p>
  
  <p>How can I combine the two queries?</p>