TL/DR: I am unable to get a reference property to be recognised as part of a
query filter.
I have a datastore thats filled with ~850 groups and ~19,000 items. Each
item may belong to only one group, I have two models in my app that
represent a Group and an Item:
class Group(db.Model):
Id = db.IntegerProperty()
Name = db.StringProperty()
# ... some other properties
class Item(db.Model):
Id = db.IntegerProperty()
Name = db.StringProperty()
Group = db.ReferenceProperty(Group, collection_name="groupItems")
# ... some other properties
I can use the datastore admin to view a specific item (i.e. WHERE Id = 34)
and see that it is connected correctly to a Group -
SELECT * FROM Item WHERE Id = 34
This gives me a group with the following properties:
*Decoded entity key:* *Group:
id=10321*<https://appengine.google.com/datastore/edit?app_id=s%7Eeve-miner&namespace=&version_id=eve-copilot-live.353587300539242520&key=agtzfmV2ZS1taW5lcnIMCxIFR3JvdXAY0VAM>
**
***Entity key:* agtzfmV2ZS1taW5lcnIMCxIFR3JvdXAY0VAM
* Id:* 18
If I alter my GQL query to retrieve all items for this Group I get no
results! -
SELECT * FROM Item WHERE Group =
KEY('agtzfmV2ZS1taW5lcnIMCxIFR3JvdXAY0VAM') -- No Results
SELECT * FROM Item WHERE Group = KEY('Group',
'agtzfmV2ZS1taW5lcnIMCxIFR3JvdXAY0VAM') -- No Results
If I retrieve just the group, it works as expected -
SELECT * FROM Group WHERE __key__ =
KEY('agtzfmV2ZS1taW5lcnIMCxIFR3JvdXAY0VAM') -- Returns 1 Group
This equally applies in my Python code. Calling:
group = Group.gql("WHERE Id = :1", 18).get()
items = Item.gql("WHERE Group = :1", group).fetch(50)
results in a list containing no items. Similarly
group.groupItems.fetch(500) -- Returns no results
My question is - am I doing something particularly stupid? I have created a
dummy project with a similar structure to prove to myself that it wasnt a
naming problem (i.e. that Group wasn't a reserved word) and that returns
just fine. (Attached if anyone is interested).
What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-appengine/-/mdUoBVcmLKMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.