我正在测试以下对象:
pk = ndb.Key(League, 'Premier League', 'Season', '2012/13')
o = Team(
id = 'Chelsea',
name ='Chelsea',
leagues = [
TeamInLeague(
parent = pk,
position = 1,
),],
)
o.put()
并且以下测试失败AssertionError: 0 != 1
:
q = Team.query(ancestor=pk)
self.assertEqual(q.count(), 1)
我还尝试了以下测试:
q = Team.query(TeamInLeague(ancestor=pk))
self.assertEqual(q.count(), 1)
它失败了AttributeError: type object 'TeamInLeague' has no attribute 'ancestor'
。
有没有办法通过结构化属性的父级查询?还是我做错了?我从文档中了解到我在创建时添加了父属性。