Python 3.x 极限关系
我有两个表,即Order和OrderTransaction,其中Order-to-Order事务是一对多关系。我必须在订单表中获取订单事务作为关系。如何将订单事务的数量限制为特定的数量(如3),而不是为订单提取所有事务Python 3.x 极限关系,python-3.x,sqlalchemy,Python 3.x,Sqlalchemy,我有两个表,即Order和OrderTransaction,其中Order-to-Order事务是一对多关系。我必须在订单表中获取订单事务作为关系。如何将订单事务的数量限制为特定的数量(如3),而不是为订单提取所有事务 class Order(Base): orderTransactions = relationship( "Order", uselist=True, lazy="joined" ) 当我基于主键订单id获取订单时,我只需要获
class Order(Base):
orderTransactions = relationship(
"Order", uselist=True,
lazy="joined"
)
当我基于主键订单id获取订单时,我只需要获取orderTransactions关系中的3个事务。如何实现这一点?上述问题的解决方法是使用延迟加载作为动态加载
class Order(Base):
orderTransactions = relationship(
"Order", uselist=True,
lazy="dynamic"
)
因为我只需要获取3个订单交易,所以每当我需要订单交易时,我都会这样做
transactions = order.orderTransactions[0:3]