Hi Jeff,

On Mon, Jun 15, 2009 at 5:28 PM, Jeff Enderwick <[email protected]>wrote:

>
> Apologies in advance if this is obvious to the experienced Python
> programmer. It is clear that 20+yrs of C has worn grooves in my brain:
>
> class ClassA(db.Expando):
>  extref = db.ReferenceProperty(ClassB)
>
> ...
> class ClassB(db.Expando):
>  extref = db.ReferenceProperty(ClassA)
>
> is what I want.


Unfortunately, a class has to be defined before you can reference it, which
prohibits explicit mutual references like this. The easiest way around it is
this:

---
class ClassA(db.Model): # Or use db.Expando if you want
  extref = db.ReferenceProperty() # Can now reference _any_ model.

class ClassB(db.Model):
  extref = db.ReferenceProperty(ClassA)
---

A bit of extra hackery that I can't really recommend, but ought to have the
desired effect:

---
refprop = ClassA.properties()['extref']
refprop.data_type = refprop.reference_class = ClassB
---


> Putting a:
>
> class ClassB(db.Expando): pass
>
> at the top seems to do the trick when playing w/Python, but GAE throws
> a KindError on assignment, so clearly this ain't right...


That's because ClassA's ReferenceProperty gets a reference to the class
assigned the name 'ClassB' in the namespace at the time its definition is
processed; you subsequently assign a new class to that name, but the new
class has no relation to the old one. Dynamic languages can be screwy like
that. ;)

-Nick Johnson


>
> Thanks,
> Jeff
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to