App Engine handles what Rails calls "polymorphic association". An
example:
class Rating(db.Model):
rating = db.RatingProperty()
rated_obj = db.ReferenceProperty(required=True)
Since I didn't specify a particular model for the ReferenceProperty, I
can use any kind of model. App Engine uses keys. In Rails this would
be done by two fields:
rated_obj_id --> integer
rated_obj_type --> string describing the type or class so Rails
knows which table to use
In some of my App Engine models, I find myself adding a "type" string
property whenever I have a general reference property. I think this
is needed to do queries on just certain kinds of references.
So I would do this:
class Rating(db.Model):
rating = db.RatingProperty()
rated_obj = db.ReferenceProperty(required=True)
rated_obj_kind = db.StringProperty()
Now I can easily query for all ratings on a particular kind of class
by using a filter("rated_obj_kind =", "Foo"). It seems a bit wasteful
since the kind information is already in the reference key. Am I
missing a query to get at kind from the keys? Or should I just auto-
initialize rated_obj_kind when rated_obj is set?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---