Filter on property.key?

2 views
Skip to first unread message

Aaron Krill

unread,
Apr 15, 2008, 5:47:42 PM4/15/08
to google-a...@googlegroups.com
I have a ReferenceProperty and I'd like to be able to filter on it. Is this possible?

ryan

unread,
Apr 15, 2008, 9:02:45 PM4/15/08
to Google App Engine
Yes, filtering on reference properties in queries works just like
filtering on other property types. You just need to use a Key as the
filter value.

Diz

unread,
May 17, 2008, 1:09:09 PM5/17/08
to Google App Engine
Hello,

could you please provide brief example of code with filter on
ReferenceProperty?

Thank you in advance.

ryan

unread,
May 18, 2008, 1:17:21 PM5/18/08
to Google App Engine
sure! i haven't tested this, but here goes:

class Foo(db.Model):
pass

class Bar(db.Model):
foo = db.ReferenceProperty(Foo)

key = Foo().put()
query = Bar.gql('WHERE foo = :1', key)

Mahmoud

unread,
May 19, 2008, 9:34:09 AM5/19/08
to Google App Engine
You do not have to explicitly use a key, you can just pass an instance
of Foo, and the AppEngine will implicitly use the key under the hood.
You can also use:
foo = Foo()
foo.put()
query = Bar,gql('WHERE foo = :1', foo)
Reply all
Reply to author
Forward
0 new messages