title: Accessing Relationship Table data in sqlalchemy with API
body: <p>I have the following association table defined in my postgres database. </p>
  
  <pre><code>student_tests_association_table =db.Table('student_tests',
                      db.Column('students_id', db.Integer, db.ForeignKey('students.id')),
                      db.Column('tests_id', db.Integer, db.ForeignKey('tests.id'))
  </code></pre>
  
  <p>and I want to add these non-foreign keys to the table so that I can access the scores from a particular test taken by a particular student. </p>
  
  <pre><code>                    db.Column('MathNC_Score', db.Integer),
                      db.Column('MathC_Score', db.Integer),
                      db.Column('Reading_Score', db.Integer),
                      db.Column('Writing_Score', db.Integer))) 
  </code></pre>
  
  <p>If I did this, how would I access the data above? 
  For example, if I defined a function to be: </p>
  
  <pre><code>def get_score(subject):
          return student_tests_association_table.c.[subject]
  </code></pre>
  
  <p>it would be accessing the whole column, so if I wanted to just get one score, i.e 'MathC_Score', for test_id = 1, how would it look? </p>
  
  <p>Also if I wanted to add all of the scores for one test, would the function look something like... </p>
  
  <pre><code> def get_total_score():
          for c in student_tests_association_table:
              if c.key == 'students_id' or 'tests_id':
                  pass 
              else: 
                  sum = sum + c 
              return sum
  
  </code></pre>
  
  <p>Edit: Afterthought
  Or would it make more sense to have the scores be included in the Test database model? But since for each student having a unique score for each Test, it doesn't make much sense to me. </p>