0

This AppEngine task seems like it should be trivial to do but I haven't quite worked it out. I have some data in a GrandParent/Parent/Child relationship thus:

EntityName  Key
----------- -------
GrandParent W
GrandParent X
Parent      W.A
Parent      X.A
Parent      X.B
Child       W.A.i
Child       X.A.i
Child       X.A.ii    <=== matches X.*.ii
Child       X.A.iii
Child       X.B.i
Child       X.B.ii    <=== matches X.*.ii

I'm trying to construct a query that matches all children with keys X.*.ii. In other words, it would return the keys X.A.ii and X.B.ii from the above, and nothing else. I'm using the low-level query mechanism, and what I have so far is this:

Entity gpX = new Entity("GrandParent","X");
Query q = new Query("Child");
q.setAncestor(gpX.getKey());

Which returns five children. If the i/ii/iii attribute was a property and not a key this would be trivial, but it is a key, and it is not clear to me how to specify that 'ii' is a search criterion.

user939737
  • 113
  • 1
  • 1
  • 4

1 Answers1

0

There's no way to do this without a separate property. All filters in the App Engine datastore have to be either equality or range tests (which are equivalent to string prefix tests); it's not possible to filter in the way you're describing using a single filter.

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • But couldn't I do this if "ii" was in property Child.Foo, via q.setFilter("Foo","ii")? Assuming that's the case, my problem would appear to reduce to identifying Child.Key as the filter field instead of Child.Foo. – user939737 Jun 14 '12 at 23:23
  • Yes. That's why my answer started with "There's no way to do this without a separate property". The key pseudo-property contains the entire key, not just the ID/name you're trying to filter on. – Nick Johnson Jun 14 '12 at 23:47