title: Access/Query List of Object SQLAlchemy
body: <p>I have a relationship that yields a list of objects</p>
  <pre class="lang-py prettyprint-override"><code>class Category(db.Model):
    _id = db.Column(&quot;id&quot;, db.Integer, primary_key = True)
    book_category = db.Column(&quot;book_category&quot;, db.String)
    booklist = db.relationship('Books', backref = &quot;book_category&quot;)
    def __init__(self, book_category):
      self.book_category = book_category
  class Books(db.Model):
    _id = db.Column(&quot;id&quot;, db.Integer, primary_key = True)
    bookname = db.Column(&quot;bookname&quot;, db.String)
    filename = db.Column(&quot;filename&quot;, db.String)
    category = db.Column(db.Integer, db.ForeignKey('category.book_category'))
    def __init__(self, bookname,filename):
      self.bookname = bookname
      self.filename = filename
  
  </code></pre>
  <p>So when I'm querying the category I have an access to category.booklist</p>
  <p>Which would yield something like this</p>
  <pre class="lang-py prettyprint-override"><code>[&lt;book1&gt;, &lt;book3&gt;, &lt;book4&gt;]
  </code></pre>
  <p>I can access each using <em>for loop</em> however, I'm feeling that it is not the most efficient way to do.</p>
  <p>Is there any way that I can do like</p>
  <p>category.booklist.query.filter(books.bookname == variable).all()</p>
  <p>Querying and filtering the list of objects yielded by category.booklist</p>