Reputation: 5338
Assuming I have the following (simplified) models in a GAE Java application:
Entity project = new Entity("Project")
project.setProperty("name", "test");
and
Entity task = new Entity("Task");
task.setProperty("name", "test");
task.setProperty("project", project.getKey());
How do I get all Task
s that have a reference to a specific Project
?
I've tried
Query q = new Query("Task");
Query.FilterPredicate projectFilter =
new Query.FilterPredicate("project",
Query.FilterOperator.EQUAL,
project.getKey()
);
q.setFilter(projectFilter);
But to no avail.
I've check the actual data with the Datastore viewer and everything is in place.
Task
s have a proper Key
to a project and all of the properties are indexed.
The only thing that seems out of the ordinary, is the fact that (considering my app supports multi-tenancy), that Project
key as a namespace prefix on the viewer.
Could that be the problem, and is there any solution?
Many thanks in advance.
Upvotes: 0
Views: 376
Reputation: 2060
try to use project.getKey().getId()
instead,
or use the special key filter: Entity.KEY_RESERVED_PROPERTY
which is described here:
https://developers.google.com/appengine/docs/java/datastore/queries#Key_Filters
Upvotes: 1