1
我想在預算應用程序中顯示「最後條目」列表。這些條目(如費用,收入,賬戶轉賬,貸款)具有除user_id之外定義的不同列。SQLAlchemy中的完全聯接?
在SQL中,我會去一個完整的聯接,但我正在使用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)
我用它來構建完整的聯接語句http://sqlalchemy.readthedocs.org/en/rel_0_6/core/compiler.html – jdurango 2013-10-18 16:16:52