我使用 SQLAlchemy 用 Python 编写了这些代码。
dailyCashFlow = models.DailyCashFlow(day=day, cash_start_of_day = cash_start_of_day, cash_end_of_day = cash_end_of_day)
branch.dailyCashFlow.append(dailyCashFlow)
db.session.commit()
result['result'] = True
result['message'] = string.join(['Daily cashflow saved successfully with ID=#'], `dailyCashFlow.id`)
关系大致是:company->branches->dailyCashflow。我想获取新插入的dailyCashFlow.id 的id。我想我可以轻松地参考 dailyCashFlow 对象来获取 id,但事实并非如此。它使用模型中设置的lazy='dynamic'。是这个原因吗?而且,如何轻松获取新插入数据的 id?