2016-10-04 68 views

回答

3

有這樣的文檔的example

from sqlalchemy.util import OrderedDict 
from sqlalchemy.orm.collections import MappedCollection 

class NodeMap(OrderedDict, MappedCollection): 
    """Holds 'Node' objects, keyed by the 'name' attribute with insert order maintained.""" 

    def __init__(self, *args, **kw): 
     MappedCollection.__init__(self, keyfunc=lambda node: node.name) 
     OrderedDict.__init__(self, *args, **kw) 

使用方法很簡單:

foo = relationship(..., collection_class=NodeMap) 
+0

在這裏,我想通過我的所有文檔的閱讀,一定是錯過了這個...謝謝男人,併爲麻煩抱歉 –