我迷路了,我想要做一些類似下面的過濾ID。谷歌應用程序引擎:按ID篩選
id = 1000
query = Customers.all()
query.filter('ID =', id)
或
query = db.GqlQuery("select * from Customers where ID = %s" % id)
什麼是通過ID來篩選正確的方法?
我迷路了,我想要做一些類似下面的過濾ID。谷歌應用程序引擎:按ID篩選
id = 1000
query = Customers.all()
query.filter('ID =', id)
或
query = db.GqlQuery("select * from Customers where ID = %s" % id)
什麼是通過ID來篩選正確的方法?
都是正確的,甚至Customers.gql(「WHERE ID =:1」,id);
編輯:如果ID是自動生成的ID屬性,你應該使用Customers.get_by_id()
我有這個同樣的問題,事實證明,我只是工作太辛苦了。答案在於getObjectById()。如果這對你有用,請去my very-similar S.O. question,並給予戈登的回答,因爲他是向我展示這件事的人。
Player result = null;
if (playerKey == null)
{
log.log(Level.WARNING, "Tried to find player with null key.");
}
else
{
PersistenceManager pm = assassin.PMF.get().getPersistenceManager();
try {
result = (Player) pm.getObjectById(Player.class, playerKey);
} catch (javax.jdo.JDOObjectNotFoundException notFound) {
// Player not found; we will return null.
result = null;
}
pm.close();
}
return result;
heh。糟糕,對不起 - 我只注意到你想要python,而且我給了你Java。那麼,我確定在python API中也有一個getObjectByID方法。祝你好運! – Olie 2010-09-25 15:48:15
你需要使用Customers.get_by_id(id)
我是否需要設置index.yaml以使此函數可以使用默認ID? – 2013-05-04 16:16:13
我試過,但都沒有返回結果,所以我不知道什麼是ID的正確語法? – Peter 2010-08-09 09:17:43
我是否需要在index.yaml中寫入某些內容以使get_by_id函數與默認ID一起工作? – 2013-05-04 16:19:08