Reputation: 3941
I would like to display a list of "last entries" in a budget app. The entries (like expenses, income, account transfers, loans) have different columns defined apart from a user_id.
In SQL I would go for a FULL JOIN, but I am using SQLAlchemy (declarative). What is the correct approach here? Some meta table?
Thanks a lot.
Example tables:
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)
Upvotes: 1
Views: 2277
Reputation: 2348
You'll have to use raw SQL if your database supports it or an union otherewise. from http://groups.google.com/group/sqlalchemy/msg/80ea8e712380bff4
Upvotes: 3