1
Я пытаюсь сделать следующее присоединиться к SQLAlchemySQLAlchemy за несколькими столами присоединяется
select * from splits s
join transactions t on t.guid = s.tx_guid
join accounts a on a.guid = s.account_guid
left join splits s2 on s2.tx_guid = t.guid
join accounts a2 on a2.guid = s2.account_guid
where a.name = 'Checking Account' and t.post_date > '2012-02-29'
order by t.post_date desc
с использованием этих моделей
class Account(db.Model):
__table__ = db.Table('accounts', db.metadata, autoload=True, autoload_with=db.engine)
splits = db.relationship('Split', backref='account')
class Transaction(db.Model):
__table__ = db.Table('transactions', db.metadata, autoload=True, autoload_with=db.engine)
splits = db.relationship('Split', backref='transaction')
class Split(db.Model):
__table__ = db.Table('splits', db.metadata,
db.Column('tx_guid', db.VARCHAR, db.ForeignKey('transactions.guid')),
db.Column('account_guid', db.VARCHAR, db.ForeignKey('accounts.guid')),
autoload=True, autoload_with=db.engine)
я получил, насколько это, но теперь я застрял
q = Split.query.join(Transaction). \
join(Account). \
options(db.joinedload(Split.transaction)). \
options(db.joinedload(Split.account)). \
filter(Account.name == 'Checking Account'). \
filter(Transaction.post_date > date(2012, 02, 29)). \
order_by(db.desc(Transaction.post_date))
Как я могу присоединиться операции с расщепления, а затем разделяет с счетами, то есть последними двумя соединениями запроса выше?