tags:

views:

42

answers:

2

Hi

I am lost somehow, I want to do something like below which filter by the ID.

id = 1000
query = Customers.all()
query.filter('ID =', id)

or

query = db.GqlQuery("select * from Customers where ID = %s" % id)

What is the correct method to filter by ID?

+1  A: 

both are correct and even Customers.gql("WHERE ID = :1", id);

Edit: If ID is the automatically created id property you should use Customers.get_by_id()

gustavogb
I tried that but all return no result, so I wonder what is the correct syntax of ID?
Peter
A: 

I had this same problem, and it turned out that I was just working too hard. The answer lies in getObjectById(). If this works for you, please go to my very-similar S.O. question and give Gordon's answer a vote-up, since he's the one who showed me this.

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;
Olie
Heh. Oops, sorry -- I just noticed that you wanted python and I gave you Java. Well, I'm sure there is a getObjectByID method in the python APIs, too. Good luck!
Olie