如何在 ZODB 中实现持久列表或持久映射
一对多关系在 ZODB 中不起作用,因为列表是可变的。他们说解决方案是持久映射或持久列表或 BTree。有人可以告诉我它到底是如何完成的吗
One to many relationships not working in ZODB as list is mutable.They say solution is Persistent Mapping or Persistent List or BTree.Can someone please tell me how is it exactly done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解你的问题。
PersistentMapping 的行为就像字典一样,但它是持久的。 PersistentList 只是一个持久列表。
BTree 也充当字典,但它针对大量对象进行了优化。如果您必须处理许多对象,则不应使用 PercientMapping 或 PercientList。
对于 ZODB 关系,您可以使用对象引用就像您通常在 Python 中所做的那样。
如果需要的话,ZODB 甚至支持弱引用。
还有其他专门的包,例如 z3c.relationfield,用于处理 ZODB 中的关系,例如,如果您需要按关系搜索,但我从未需要使用它们。
I'm not sure I understand your question.
A PersistentMapping behaves just as a dictionary but is persistent. A PersistentList is just a that, a list that is persistent.
A BTree behaves also as a dictionary but it's optimized for huge numbers of objects. You shouldn't use PersistentMapping or PersistentList if you have to deal with many objects.
For ZODB relations you can use object references as you would normally do in Python.
ZODB even supports weak references if you need them.
There are other specialized packages, like z3c.relationfield, to deal with relations in ZODB, like for example if you need to search by relation but I never had the need to use them.