Hi I was wondering if anyone knows of the most efficient way to find out if a column has a foreignKey relationship or not.
class StudentIntendCourse(DeclarativeBase):
__tablename__ = 'studentIntendCourse'
id = Column(Integer, primary_key=True)
studentID = Column('studentID',Integer,ForeignKey('student.id'))
courseID = Column('courseID',Integer,ForeignKey('course.id'))
course = relationship("Course",backref="studentIntendedCourses")
I would like to find out if is_foreign_key(StudentIntendCourse.studentID)?
The ForeignKey objects associated with an individual Column object are available in the foreign_keys collection of that column.
foreign_keys_set = StudentIntendCourse.__table__.c.studentID.foreign_keys
You can check if this set is non empty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With