Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否将OrderedDict用于SQLAlchemy关系()?_Python_Python 3.x_Sqlalchemy - Fatal编程技术网

Python 是否将OrderedDict用于SQLAlchemy关系()?

Python 是否将OrderedDict用于SQLAlchemy关系()?,python,python-3.x,sqlalchemy,Python,Python 3.x,Sqlalchemy,可以告诉SQLAlchemy使用OrderedDict进行关系存储吗?我只熟悉属性映射集合,但这是无序的。文档中有这样一个例子: from sqlalchemy.util import OrderedDict from sqlalchemy.orm.collections import MappedCollection class NodeMap(OrderedDict, MappedCollection): """Holds 'Node' objects, keyed by the

可以告诉SQLAlchemy使用OrderedDict进行关系存储吗?我只熟悉属性映射集合,但这是无序的。

文档中有这样一个例子:

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)

在这里我想我读了所有的文件,一定错过了这个。。。谢谢你,伙计,很抱歉给你添麻烦