问题
I want a list of all my model entities. Model.all() returns a gqlquery. I know that I can then do list comprehension on the query and end up with the result I am seeking. Is there not a way already built-in saving the additional step of doing the comprehension?
Or is everyone just subclassing and building the method in themselves? ... or is this a safety measure preventing us from accessing more data then we intended incurring costs?
Thanks
回答1:
To get to the entity you need a key. If you only have a kind of the entity, then GAE needs to go through indexes to find all keys, e.g. it uses Metadata Queries.
Metadata queries give you the option to query by namespace, kind and property.
回答2:
you have 2 options:
- use fetch() and get a defined number of entities like Model.all().fetch(100)
- use Model.all() and loop over the query.
来源:https://stackoverflow.com/questions/9824317/can-you-get-all-entities-of-a-model-in-appengine-and-not-a-gqlquery