我有一个适用于所有联系人的多模型
from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel
class Contact(polymodel.PolyModel):
telephone = ndb.StructuredProperty(Telephone, repeated=True)
email = ndb.StructuredProperty(Email, repeated=True)
Telephone和Email模型类有两个简单的StringProperty
属性:type
和{
我有一个模型Person
,他使用这个多模型:
我想用投影来减少输出量。因此,当我查询父对象的属性(即polymodel)时,例如:
qry = Person.query(projection=['telephone.value'])
一切正常。但是如果我查询Person
类的属性,(其中之一)
qry = Person.query(projection=['name'])
qry = Person.query(projection=[Person.name])
我收到一个InvalidPropertyError: Unknown property name
异常。在
这是ndb的一个缺陷,只关注类而不是实际的类?在
请让我知道是否有办法绕过它(当然一个是不要使用多模型)。谢谢。在
编辑:
下面我给出了一个更简单的模型(删除了StructuredProperty
),它给出了相同的问题:
class Contact(polymodel.PolyModel):
telephone = ndb.StringProperty()
class Person(Contact):
name = ndb.StringProperty()
这是有效的:
qry = Person.query(projection=['telephone'])
这不起作用:
qry = Person.query(projection=['name'])
尝试将StructuredProperty与PolyModel结合起来有很多问题,比如ndb.StructuredProperty not calling ndb.PolyModel subclass methods和{a2}。在
基本上,多模型和结构属性的设计倾向于排除它们的结合使用。在
我知道你的问题是关于投影查询的,但是这里的基本问题无疑会阻碍投影查询的工作。在
相关问题 更多 >
编程相关推荐