Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:50:34+00:00 2026-05-24T09:50:34+00:00

Let’s assume we have two models: User and Token . A user may have

  • 0

Let’s assume we have two models: User and Token. A user may have only one Token, and a Token can belong to only one user.

Coming from relational databases, the following seems like the way to do it:

class User(db.Model):
    name = db.StringProperty()

class Token(db.Model):
    name = db.StringProperty()
    owner = db.ReferenceProperty(User)

This will of course create User.token_set as well, which is a db.Query.
But I’d really like to access the token with just, say, User.token instead of User.token_set.get(), so how about..

class User(db.Model):
    name = db.StringProperty()
    token = db.ReferenceProperty(Token)

class Token(db.Model):
    name = db.StringProperty()
    owner = db.ReferenceProperty(User)

Now I can access them in a bidirectional fashion: User.token & User.owner. And just ignore the fact that I have those automatically-created .token_set and user_set.

Is there anything wrong with this? On the logic side, on the performance side?

Maybe I shouldn’t even have two models. They both, in practice, contain four-five properties. Should they just be one? When’s a one-to-one relationship supposed to be ditched in just merged into one model?

Thanks for any input at all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:50:36+00:00Added an answer on May 24, 2026 at 9:50 am

    this is the appengine data store. it’s not sql. you should group together data as it is used by your system. presumably you have places where users and tokens are used together, and since there are no issues with many-to-one these can go in the same model instance. this will give you better performance (much simpler retrieval of user by token, for example) and easier handling of consistency (updating token and user will be within a single transaction).

    i don’t know if self-linking is acceptable here, so perhaps someone will edit this if not, but i wrote http://acooke.org/cute/LessonsLea2.html to try collect together my experience with the data store. you might find it useful.

    [edit: one way to think about this: you’re not modeling data. you’re writing a system that is intended to scale. that – and not modeling data – is what drives everything. i am not saying this is a good idea, but it’s what appengine does. if your main priority is modeling data – for example, if you want to have multiple applications using your data in different ways – then you shouldn’t be using appengine.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two entities: Physician Credentials And a physician can have many
Let us assume I have two classes: class Base{}; class Derived: public Base{}; none
Let's say I have two files.. I want to compare them side-by-side and see
let's say i have three tables, each one relates to another, when i need
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have a dataset, which can be neatly classified using weka's J48
Let say I have two UIViews: View1: - bounds: 0, 0, 20, 20 -
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's suppose I have a trait with two type parameters, e.g. trait Qux[A, B]
Let me explain my situation. I have made a user control that contains an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.