Consider a classic setting of two tables - user
and api_key
, represented by SQLAlchemy objects as:
I would add an api_key relationship on User
:
class User(Base):
__tablename__ = 'user'
user_id = Column(String)
user_name = Column(String)
vioozer_api_key = Column(String, ForeignKey("api_key.api_key"))
api_key = Relationship('ApiKey', uselist=False)
Then you can do a query like this:
>>> user = database.db_session.query(User)\
.filter(User.user_id=='user_00000000000000000000000000000000').first()
>>> user.api_key