Model design pattern for google app engine

早过忘川 提交于 2019-12-08 06:42:59

问题


I am building an app on google app engine which has three different kind of Users(ABC,LMN,XYZ).
This is how my model looks like

User(db.Model):
   email = db.EmailProperty()
   username = db.StringProperty()
   password = db.StringProperty()
   role = db.IntegerProperty()

## role = 1 for ABC;2 for LMN;3 for XYZ

ABC(User):
    name = db.StringProperty()
    isSuperHero = db.BooleanProperty()

LMN(User):
    nickname = db.StrngProperty()
    profession = db.StringProperty()
#   some other random property

XYZ(User):
    department = db.StringProperty()
    salary = db.FloatProperty()
    

I want to provide a single login page wherein all the three users will be able to login to the app.
In the datastore i will have 4 different entity User,ABC,LMN,XYZ records.
There are two approaches as I see :

  • 1st approach is by extending the User model: This approach has the disadvantage of storing redundant information(username..etc) in User as well as the other 3 entities.
  • 2nd approach is by keeping a reference of User in the three entities(thereby eliminating the redundant columns). The disadvantage I see is that to get the User's email i need to get the User's reference(cost involved is high i guess)

So, the question boils down to the basic fundamental: Should I store the redundant columns in all the entities OR should i store a reference of the respective User in the entities. Can someone provide some example of what will be the data cost(read/write) difference for both the approach?

来源:https://stackoverflow.com/questions/15588836/model-design-pattern-for-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!