2
votes

What is the difference between the following two query methods with filters?

@classmethod
def get_by_user_id(cls, ancestor_key, user_id):
    return cls.query(cls.user_id==user_id, ancestor=ancestor_key).get()

and

@classmethod
def get_by_user_id(cls, ancestor_key, user_id):
    return cls.query(user_id=user_id, ancestor=ancestor_key).get()

Seems to give the same results, which are entries filtered by the value of user_id. Thanks.

1

1 Answers

4
votes

You will find there is no difference for this simple case. The second is just a shortcut for the first style using keyword args to look up property names.

However you can't use the second style the minute you want to to inequality filters < , use IN() operator or sort orders.

When you use an expression you get a FilterNode or PropertyOrder instance created. e.g

dev~cash-drawer> models.InvoiceItem.price == 100
FilterNode('price', '=', 10000)

dev~cash-drawer> models.InvoiceItem.price.IN([100,])
FilterNode('price', '=', 10000)

dev~cash-drawer> -models.InvoiceItem.price
PropertyOrder(<price>, DESCENDING)

Which are all things you can't express with just keyword arguments.