title: Flask-SQLAlchemy: multiple filters through one relation
body: <p>I have two models, Tags and Photos, that have a many-to-many-relationship like so:</p>
  
  <pre><code>tag_identifier = db.Table('tag_identifier',
                            db.Column('photo_id', db.Integer, db.ForeignKey('photo.id')),
                            db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'))
                           )
  
  class Tag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
  
  class Photo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    tags = db.relationship('Tag', secondary=tag_identifier,
                           backref=db.backref('photos', lazy='dynamic'), lazy='dynamic')
  </code></pre>
  
  <p>I am trying to query all photos that have multiple specific tags. For example, if I was to query all photos with <code>&lt;Tag 1&gt;</code> <strong>and</strong> <code>&lt;Tag 2&gt;</code>:</p>
  
  <hr>
  
  <p><code>Photo.query.join(Photo.tags).filter(Tag.id==1).all()</code> would return</p>
  
  <p><code>[&lt;Photo 1&gt;, &lt;Photo 2&gt;, &lt;Photo 3&gt;, &lt;Photo 4&gt;]</code>, and </p>
  
  <p><code>Photo.query.join(Photo.tags).filter(Tag.id==2).all()</code> would return</p>
  
  <p><code>[&lt;Photo 1&gt;, &lt;Photo 2&gt;, &lt;Photo 5&gt;, &lt;Photo 6&gt;]</code>.</p>
  
  <hr>
  
  <p>In this example, what operation would I need to do in order to get the following result:
  <code>[&lt;Photo 1&gt;, &lt;Photo 2&gt;]</code></p>