title: Flask SQLAlchemy filter records from foreign key relationship
body: <p>I have 2 models:</p>
  
  <pre><code>class Scenario(db.Model):
      __tablename__ = 'scenarios'
      scenario_id = db.Column(db.Integer, primary_key=True)
      scenario_name = db.Column(db.String(120))
      scenario_text = db.Column(db.Text)
      hints = db.relationship('Hint', backref='scenario', lazy='dynamic')
  
      def __init__(self, scenario_name, scenario_text):
          self.scenario_name = scenario_name
          self.scenario_text = scenario_text
  
      def __repr__(self):
          return "&lt;Scenario(scenario_name='%s', scenario_text='%s', hints='%s')&gt;" % self.scenario_name, self.scenario_text, self.hints
  
  class Hint(db.Model):
      __tablename__ = 'hints'
      hint_id = db.Column(db.Integer, primary_key=True)
      scenario_id = db.Column(db.Integer, db.ForeignKey('scenarios.scenario_id'))
      hint = db.Column(db.Text)
      release_time = db.Column(db.Integer)    
  
      def __init__(self, scenario_id, hint, release_time):
          self.scenario_id = scenario_id
          self.hint = hint
          self.release_time = release_time
  
      def __repr__(self):
          return "&lt;Hint(scenario_id='%s', hint='%s', release_time='%s')&gt;" % self.scenario_id, self.hint, self.release_time
  </code></pre>
  
  <p>I want to be able to get all the scenarios with their corresponding hints but only the hints that have a release_time less than the current time.</p>
  
  <p>I figured this would work:</p>
  
  <pre><code>scenarios = Scenario.query.filter(Scenario.hints.release_time &lt; time.time())
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Scenario.hints has an attribute 'release_time'
  </code></pre>
  
  <p>I just started playing around with Flask and SQLAlchemy. Any advice would be appreciated.</p>