EDIT2:啊,遮GQL在數據瀏覽器使用...
這裏有一種方法:
1)運行此並獲得ID號:
SELECT * FROM Author where name = 'shakespeare'
2 )從以前的查詢中使用的ID號,這條命令:
SELECT * FROM Story where author = key('Author', 12345)
編輯:終於,在RA w GQL:
(最簡單的方法:使用隱式反向引用屬性名稱; 。在形式 「modelname_set」)
qry = GqlQuery("SELECT * FROM Author WHERE name = :1", "shakespeare")
shakespeare = qry.get()
shakespeare.story_set # this property now contains all Shakespeare's stories
或
qry0 = GqlQuery("SELECT * FROM Author WHERE name = :1", "shakespeare")
shakespeare = qry0.get()
qry1 = GqlQuery("SELECT * FROM Story WHERE author = :1", shakespeare.key())
shakespeare_stories = qry1.fetch(10) # probably good to have some limit here
我更喜歡這種方式:
qry = Author.all()
qry.filter('name = ', 'shakespeare')
shakespeare = qry.get()
shakespeare.story_set # this property now contains all Shakespeare's stories
的更復雜的方式有時可能是必需的:
qry0 = Author.all()
qry0.filter('name = ', 'shakespeare')
shakespeare = qry0.get()
qry1 = Story.all()
qry1.filter('author = ', shakespeare.key())
shakespeare_stories = qry1.fetch(10) # probably good to have some limit here
我正在尋找原始的GQL方式,我知道如何做Pythonic的方式。 – 2010-02-17 02:36:41
@Thierry:的確是你;請參閱上面編輯的答案。 – bernie 2010-02-17 04:28:26
我從數據查看器運行GQL,它爲您提供了一個可以運行查詢的窗口。我不認爲我可以從那裏運行Python代碼。 – 2010-02-17 13:29:51