How to properly use association_proxy and ordering_list together with SQLAlchemy

前端 未结 1 1470
小鲜肉
小鲜肉 2021-02-04 05:37

Based on some posts on the SQLAlchemy Google Group:

https://groups.google.com/forum/#!topic/sqlalchemy/S4_8PeRBNJw https://groups.google.com/forum/#!topic/sqlalchemy/YRy

1条回答
  •  孤独总比滥情好
    2021-02-04 06:31

    sooo close ;-)

    Please read Creation of New Values secion of association_proxy extension.
    In order to make your code work, you can either

    Option-1: add the following constructor to UserImage class:

    def __init__(self, image):
        self.image = image
    

    or

    Option-2: override the default creator with your function:

    images = association_proxy('_images', 'image',
        creator=lambda _i: UserImage(image=_i),
        )
    

    I personally favor the latter.

    0 讨论(0)
提交回复
热议问题