我有关于SQLAlchemy的问题。我如何在映射类中添加类似字典的属性,将字符串键映射为字符串值,并将其存储在数据库中(与原始映射对象位于同一表或另一个表中)。我想要添加对我的对象的任意标签的支持。SQLAlchemy - 标记字典
我发现SQLAlchemy的文档在下面的例子:
from sqlalchemy.orm.collections import column_mapped_collection, attribute_mapped_collection, mapped_collection
mapper(Item, items_table, properties={
# key by column
'notes': relation(Note, collection_class=column_mapped_collection(notes_table.c.keyword)),
# or named attribute
'notes2': relation(Note, collection_class=attribute_mapped_collection('keyword')),
# or any callable
'notes3': relation(Note, collection_class=mapped_collection(lambda entity: entity.a + entity.b))
})
item = Item()
item.notes['color'] = Note('color', 'blue')
但我想以下行为:
mapper(Item, items_table, properties={
# key by column
'notes': relation(...),
})
item = Item()
item.notes['color'] = 'blue'
有可能在SQLAlchemy的?
谢谢
那么您如何删除`i`呢?我得到一个`aise AssertionError(“依赖规则试图在实例'%s''%(r,mapperutil.state_str(dest)))```时试图清空主键列'%s'异常`s.delete i)` – Sardathrion 2011-11-24 12:48:13