Reading the following pages, I can see that I can setup relationships between tables using the orm relationship() function.
https://docs.sqlalchemy.org/en/13/orm/basic_relationships.html
https://docs.sqlalchemy.org/en/13/orm/backref.html#relationships-backref
Using this example:
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
name = Column(String)
addresses = relationship("Address", backref="user")
class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
email = Column(String)
user_id = Column(Integer, ForeignKey('user.id'))
Do I need to have an explicit user_id = Column(Integer, ForeignKey('user.id')) statement for the Address class?
Wont the relationship(backref=...) is User provide an Address.user attribute?
If the ForeignKey column is needed in Address, then why isn't it needed in User?