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

  • Home
  • SEARCH
  • 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 4583204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:10:55+00:00 2026-05-21T21:10:55+00:00

Short version of my question : What is the Gql syntax for a query

  • 0

Short version of my question: What is the Gql syntax for a query filtering based on a reference property?

Long version of my question:
Assume the following model:

Class User(db.Model):
    username = db.StringProperty()
    password = db.StringProperty()

Class Portfolios(db.Model):
    portname = db.StringProperty()

Class Portfolio_Owners(db.Model):
    port_id = db.ReferenceProperty(Portfolios)
    user_id = db.ReferenceProperty(User)
    key_string = db.StringProperty()

I want to query Portfolio_Owners based on user_id (which is a ReferenceProperty).

However, i can not query on a string of the .user_id property as you would on a StringProperty (the following returns an empty list):

key_string = 'aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM'

que=db.GqlQuery("SELECT * FROM Portfolio_Owners WHERE user_id=:1", key_string)

entity = que.fetch(limit=10)

Nor can i query on a key object of that user (the following also returns an empty list):

key_object = db.Key('aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM')

que=db.GqlQuery("SELECT * FROM Portfolio_Owners WHERE __key__=:1", key_object)

entity = que.fetch(limit=10)

And yes, I certain the user_id is correct…here is the copy-paste from the Datastore Viewer:

Entity Kind  Portfolio_Owners
Entity Key   aglwb3J0Zm9saW9yFwsSEFBvcnRmb2xpb19Pd25lcnMYhQIM
ID   261
user_id (Key)   aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM
User:           id=234

port_id (Key)   aglwb3J0Zm9saW9yEQsSClBvcnRmb2xpb3MYhAIM
Portfolios:     id=260 

I have not found the answer in App Engine docs, App Engine msg boards, or elsewhere on SO.

thanks!

  • 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-21T21:10:56+00:00Added an answer on May 21, 2026 at 9:10 pm

    So aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM is your user key, right? Let’s start with this:

    user = db.Key('aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM')
    que = db.GqlQuery("SELECT * FROM Portfolio_Owners WHERE user_id = :1", user)
    

    This should give you any Portfolio_Owners entities that refer to this user.

    You can shorten that to this:

    user = db.get('aglwb3J0Zm9saW9yCwsSBFVzZXIY6gEM')
    que = user.Portfolio_Owners_set
    

    The datastore is fundamentally very different from SQL. Based on your code samples, I think you would benefit from revisiting the docs to get a better understanding of datastore design:

    http://code.google.com/appengine/docs/python/datastore/entities.html

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

Sidebar

Related Questions

Short version: assuming I don't want to keep the data for long, how do
Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
Short Version: When I've created a Channel using ChannelFactory on a client which uses
I am writing an application to manage user access to files. The short version
Short Version I want to extend SoapClient so it does this internally when accessing
Short question : I know how to draw text on a wx.Bitmap, but how
Short version of Problem Autocomplete works when the input string matches the result string,
Short Version: I write an 8 byte, byte array filled with random bytes to

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.