title: Filtering after a join in Flask-SQLAlchemy
body: <p>I have two tables( <code>location</code> and <code>country</code> ) that am trying to query; which are represented by the models below in my flask application</p>
  
  <pre><code>from sqlalchemy import Column, DateTime, ForeignKey, Integer, \
                         Numeric, SmallInteger, String, Table
  from sqlalchemy.orm import relationship
  from sqlalchemy.schema import FetchedValue
  from flask_sqlalchemy import SQLAlchemy
  
  
  db = SQLAlchemy()
  
  
  class Country(db.Model):
      __tablename__ = 'country'
  
      country_id = db.Column(db.Integer, primary_key=True)
      country_name = db.Column(db.String(30), nullable=False)
      full_country_name = db.Column(db.String(90), nullable=False)
      country_code = db.Column(db.String(4), nullable=False)
  
      def __str__(self):
          return '%s' % self.country_name
  
      def __repr__(self):
          return '&lt;Country %r&gt;' % self.country_name
  
  
  class Location(db.Model):
      __tablename__ = 'location'
  
      location_id = db.Column(db.Integer, primary_key=True)
      location_name = db.Column(db.String(75), nullable=False)
      country_id = db.Column(db.ForeignKey('mashamba.country.country_id'), nullable=False, index=True)
  
      country = db.relationship('Country', primaryjoin='Location.country_id == Country.country_id', backref='locations')
  
      def __str__(self):
          return '%s' % self.location_name
  
      def __repr__(self):
          return '&lt;Location %r&gt;' % self.location_name
  </code></pre>
  
  <p>What am trying to do is get all columns from both tables by performing a join using the following code</p>
  
  <pre><code>Location.query.join(Country).\
                  filter_by(location_name='Cairo',
                            country_id=67).first()
  </code></pre>
  
  <p>Problem is when i run the code i get the following error </p>
  
  <pre><code>sqlalchemy.exc.InvalidRequestError: Entity '&lt;class 'app.models.Country'&gt;' has no property 'location_name'
  </code></pre>
  
  <p>Everything works fine when you run for example this code</p>
  
  <pre><code>Location.query.join(Country).all()
  </code></pre>
  
  <p>What is wrong here and how can this be solved?</p>