Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google app engine ReferenceProperty vs Key

Lets say we have following models.

    class User(db.Model):
        username=db.StringProperty()
        avatar=db.ReferenceProperty()

    class User(db.Model):
        username=db.StringProperty()
        avatar=db.StringProperty()

    class Avatar(db.Model):
        avatarLink=db.StringProperty

    class UserDataHandler:
        def adduserdata():
            userid="uniqueid1"
            avatarid="uniqueid2"
            user=User(key_name=userid)
            avatar=Avatar(key_name=user)
            avatar.avatar="http://zy.jpg"
            avatar.put()
            user.username="username"
            user.avatar=avatar
            #user.avatar=avatarid

Of the above two models of is it better to use ReferenceProperty model or store key_name of the avatar instead and get Avatar from key. By better I mean which one uses the least number of database queries.

like image 668
specialscope Avatar asked Sep 23 '26 18:09

specialscope


1 Answers

Both methods will result in the same number of queries; using a ReferenceProperty is just less code you have to write (and thus generally considered the right way to do it).

like image 69
Amber Avatar answered Sep 25 '26 07:09

Amber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!