7 messages in com.googlegroups.google-appengine[google-appengine] Re: Does getting t...| From | Sent On | Attachments |
|---|---|---|
| palp | 29 Apr 2008 00:52 | |
| Ben the Indefatigable | 29 Apr 2008 19:03 | |
| Ross Ridge | 30 Apr 2008 00:28 | |
| palp | 30 Apr 2008 01:09 | |
| Filip | 30 Apr 2008 01:18 | |
| palp | 30 Apr 2008 01:46 | |
| Filip | 30 Apr 2008 03:34 |
| Subject: | [google-appengine] Re: Does getting the key of a ReferenceProperty hit the datastore?![]() |
|---|---|
| From: | palp (palp...@gmail.com) |
| Date: | 04/30/2008 01:46:57 AM |
| List: | com.googlegroups.google-appengine |
The syntax I ended up using (which is the same as what Ross wrote above, just with the type name explicit) is: key = <EntityType>.<ReferencePropertyName>.get_value_for_datastore(<Entity>)
So if you have an entity named User with a reference property named UserType you would do something like:
theUser = User.get(userKey) userTypeKey = User.UserType.get_value_for_datastore(theUser)
On Apr 30, 1:18 am, Filip <fili...@gmail.com> wrote:
I'm sorry, could you run that by me again? What is a sample syntax that doesn't get the entity but the reference?
Filip.
On 30 apr, 10:10, palp <palp...@gmail.com> wrote:
Thanks, that worked like a charm.
On Apr 30, 12:28 am, Ross Ridge <rri...@csclub.uwaterloo.ca> wrote:
palp wrote:
This is a pretty straighforward question, but I haven't seen much detail on how ReferenceProperty actually works under the hood. I have an entity that has a reference to another entity. I want to use the application cache to minimize lookups of entities. If I do entity.reference.key(), am I saving anything at all, or does it cost the same as accessing the properties of the reference?
I don't think it saves you anything at all. Looking at the source for the ReferenceProperty class in the SDK, I think you'd have to something like this:
key = type(entity).reference.get_value_for_datastore(entity)
By accessing the property through the entity's class rather than the entity, you can get the property itself rather than entity it refers to. You can replace "type(entity)" with the name of the entiy's class.
Ross Ridge- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to goog...@googlegroups.com
To unsubscribe from this group, send email to
goog...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---




