我想在预算应用程序中显示“最后条目”列表。条目(如费用、收入、账户转账、贷款)具有除 user_id 之外定义的不同列。
在 SQL 中,我会选择 FULL JOIN,但我使用的是 SQLAlchemy(声明性)。这里的正确方法是什么?一些元表?
非常感谢。
示例表:
class Expense(Base):
__tablename__ = 'expenses'
id = Column(Integer, primary_key=True)
user = Column('user_id', Integer, ForeignKey('users.id'))
date = Column(Integer)
category = Column('category_id', Integer, ForeignKey('expense_categories.id'))
description = Column(String(50))
deduct_from = Column('account_id', Integer, ForeignKey('accounts.id'))
amount = Column(Float(precision=2))
class Loan(Base):
__tablename__ = 'loans'
id = Column(Integer, primary_key=True)
from_user = Column('from_user_id', Integer, ForeignKey('users.id'))
to_user = Column('to_user_id', Integer, ForeignKey('users.id'))
date = Column(Integer)
account = Column('account_id', Integer, ForeignKey('accounts.id'))
description = Column(String(50))
amount = Column(Float(precision=2)