title: Flask-SqlAlchemy relationship error
body: <p>Here is simple model I have </p>
  
  <pre><code>  class Record(db.Model):
        __tablename__ = 'reg_records'
        request_id = db.Column(db.Integer, primary_key = True)
        title = db.Column(NVARCHAR())
  
    class Field(db.Model):
        __tablename__ = 'reg_fields'
        request_id = db.Column(db.Integer, primary_key= True) 
        name = db.Column(NVARCHAR(), primary_key = True)
  </code></pre>
  
  <p>Now I want to map releated fields to record. I'm following flask-sqlalchemy specs and getting this</p>
  
  <pre><code>  class Field(db.Model):
        __tablename__ = 'reg_fields'
        request_id = db.Column(db.Integer, ForeignKey('record.request_id'), primary_key= True) 
        name = db.Column(NVARCHAR(), primary_key = True)
  
    class Record(db.Model):
        __tablename__ = 'reg_records'
        request_id = db.Column(db.Integer, primary_key = True)
        title = db.Column(NVARCHAR())
        fields = db.relationship(Field, backref = 'record')
  </code></pre>
  
  <p>However when I try to use this model I'm getting following error</p>
  
  <pre><code>  sqlalchemy.exc.NoForeignKeysError
    NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Record.fields - there are no foreign keys linking these tables.  Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
  </code></pre>
  
  <p>Adding <code>primaryjoin</code> to the relationship declaration like below</p>
  
  <pre><code>    fields = db.relationship(Field, backref = 'record', primaryjoin='Record.request_id==Field.request_id')
  </code></pre>
  
  <p>Doesnt solve the problem, but instead gives new exception</p>
  
  <pre><code>    sqlalchemy.exc.NoReferencedTableError
      NoReferencedTableError: Foreign key associated with column 'reg_fields.request_id' could not find table 'record' with which to generate a foreign key to target column 'request_id'
  </code></pre>
  
  <p>If I replace class names with table names in primaryjoin value, </p>
  
  <pre><code>    fields = db.relationship(Field, backref = 'record', primaryjoin='reg_records.request_id==reg_fields.request_id')
  </code></pre>
  
  <p>I'm getting one another exception</p>
  
  <pre><code>   sqlalchemy.exc.InvalidRequestError
     InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers.  Original exception was: 'Table' object has no attribute 'request_id' 
  </code></pre>
  
  <p>Overall, what is right way setting up one-to-many relationship in flask-sqlalchemy.</p>