1

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?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Sandeep
  • 803
  • 8
  • 25
  • You should probably use a PolyModel, my bet is down the track you will want to do a single query for a user by email address and you won't know the class/type of user. Using your approach will require potentially 4 queries. Also if you are starting out use ndb instead of of db. – Tim Hoffman Mar 24 '13 at 00:26
  • for the login part i am querying the User model by username and getting the role from the user entity and accordingly fetching the appropriate Entity(ABC or LMN or XYZ). My concern is that is this the right approach to move ahead. – Sandeep Mar 24 '13 at 01:07
  • That approach doesn't really make sense as each subclass will have all of the properties that the parent class has. But each is a seperate entity so you queries will be entity specific. You would either use polymodel and have just one entity for each user, or have a User object and then seperate child role entities that do not duplicate the properties. – Tim Hoffman Mar 24 '13 at 04:15
  • What are the advantage of using ndb over db? I couldn't find a single post explaining why you should use ndb over db. – Sandeep Jun 08 '13 at 21:57
  • Thats where the new work is going. For me ndb has proven to be easier (fixed things removing ReferenceProperty which auto dereferences.) Lots of little improvements, stronger async capabilities. I started using appengine in 2008. So I have a lot of development time is db, but I think its worth the shift to ndb. – Tim Hoffman Jun 08 '13 at 23:22
  • In good faith I have also migrated to ndb. One quick question over here. http://stackoverflow.com/questions/16998450/can-someone-explain-the-difference-between-this-two-ahstats-generated-timeline?noredirect=1#comment24563605_16998450 – Sandeep Jun 09 '13 at 00:15
  • You need to supply code on that other question. Can't tell what you are doing just from appstats – Tim Hoffman Jun 09 '13 at 00:50

0 Answers0