I think you can acheive the "back reference" by defining an instance  
method that returns a query object defined to search the other model  
for references to itself.   In fact I think that is all  
ReferenceProperty does anyway.

Try something like this:

class ModelA(db.Model):
    def modelB_list(self):
        if self.key():
          refs = ModelB.all()
          refs.filter('a_id_ref =', self.key().id())
          return refs
        return None

class ModelB(db.Model):
     a_ref_id = db.IntegerProperty()

ma = ModelA()
ma.put()

mb1 = ModelB(a_id_ref=ma.key())
mb2 = ModelB(a_id_ref=ma.key())
db.put([mb1,mb2])


for mb in ma.modelB_list:
   print str(mb.key())


Robert


On Nov 29, 2009, at 5:17, 风笑雪 <[email protected]> wrote:

> Of course you can use id/name to instead of reference property, but
> you can get some benefit when using reference property.
>
> One is back reference. If a reference to b, b also reference to a, you
> need store a's key in b and b's key in a.
> But using reference property, you can automatically get a back  
> reference.
> Once you need change the relationship, link a and c, you don't need
> change a, b, c at the same time(maybe a transaction), just change a's
> reference property to point to c, and everything has been done.
>
> 2009/11/29 MajorProgamming <[email protected]>:
>> I was wondering: isn't using reference properties a waste of space?
>> Wouldn't it make more sense to store the id (assuming not using
>> key_name) of the entity. After all, if the Kind is known, one can
>> easily generate the full key based on that. And with a reference
>> property it actually stores the _entire_ key (very long!).
>>
>> Why?
>>
>> --
>>
>> 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 
>> .
>>
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Google App Engine" group.
> To post to this group, send email to google- 
> [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 
> .
>
>

--

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