Hi Frank,
I reordered your mail a little bit.
On Sep 12, 9:26 pm, Frank <[EMAIL PROTECTED]> wrote:
> And the most puzzling is that this is always the same 'oParent' 150
> times, since I'm listing its children, so I would expect this
> ReferenceProperty to be cached already.
ReferenceProperty only caches for a single model, but you have 150
models, so every child will get() its parent.
> of course I am not talking about accessing the ReferenceProperty's own
> properties, I am only interested to see if it's None (and I tried with
> both '==' and 'is'), and also getting its id
> (self.oParent.key().id()), and doing one or the other gives the same
> behavior.
As soon as you access oParent it will result in a get().
Unfortunately, you can't get the key of a ReferenceProperty without
dereferencing it. Well, there is a hacky solution:
if self._oParent is None:
...
Note that most properties store their real value in
"_<property_name>", but Google might change this any time, so I
wouldn't use it in an important app.
Instead, I'd suggest you either store the str(key) in a StringProperty
and manually get() it or you use our KeyReferenceProperty from
appenginepatch's snippet library. If your parent node model is
ParentNode you could define this:
parent_key = db.StringProperty()
parent = KeyReferenceProperty('parent_key', ParentNode,
use_key_name=False)
The "parent_key" property will store the str(key) of the parent while
the "parent" property allows to access the parent directly (like with
ReferenceProperty). So, in order to test whether it's None you would
write:
if self.parent_key is None:
...
If you want to access the parent model instance you can just write
self.parent. This separation between key and model instance also makes
writing transactional code that has to pass around key_names a little
bit easier.
You can rip out the source here:
http://trac-hg.assembla.com/appenginepatch/browser/ragendja/dbutils.py
Alternatively, if you use Django you can integrate it with
appenginepatch and get the whole snippet library:
http://code.google.com/p/app-engine-patch/
But then I'd suggest you fetch the most recent source from the
repository because that contains a few additions like support for
setting the key via the KeyReferenceProperty (self.parent =
some_parent_object).
Bye,
Waldemar Kornewald
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
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
-~----------~----~----~----~------~----~------~--~---