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 5975227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:03:15+00:00 2026-05-22T21:03:15+00:00

How would I implement one-to-many on Google App Engine in the Go programming language?

  • 0

How would I implement one-to-many on Google App Engine in the Go programming language?
For example, if I have the structs below, how would I store the association of many Votes to one Comment? Would I use an array (slice) of keys to Votes in the Comment struct, or one key to the Comment from the Vote struct?

type Comment struct {
    Author  string
    Content string
    Date    datastore.Time
}

type Vote struct {
    User string
    Score int
}
  • 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-22T21:03:15+00:00Added an answer on May 22, 2026 at 9:03 pm

    The only types that are allowed for fields in the current version of the Go AppEngine SDK are as follows:

    • signed integers (int, int8, int16, int32 and int64),
    • bool,
    • string,
    • float32 and float64,
    • any type whose underlying type is one of the above predeclared types,
    • *Key,
    • appengine.BlobKey,
    • []byte (up to 1 megabyte in length),
    • slices of any of the above (up to 100 elements in length).

    Given that, there appear to be two ways to do this. One is to maintain a slice of keys to point to the Votes of a given Comment. However this is likely to run up against the 100 element limit for any reasonably popular comment.

    The other approach is to store a “pointer” to the comment in each vote struct like this:

    type Vote struct {
        User string
        Score int
        CommentKey *datastore.Key
    }    
    
    type Comment struct {
        Author  string
        Content string
        Date    datastore.Time
    }
    

    Then when you go to query it you need to do it in two steps. First you get the Comment you’re interested in (in this case just the first one that happens to be returned). Second, you query for all the votes that “point” to that comment:

    q := datastore.NewQuery("Comment").Limit(1)
    comments := make([]Comment, 0, 1)
    var err os.Error
    var keys []*datastore.Key
    if keys, err = q.GetAll(c, &comments); err != nil {
        // handle the error
    }
    
    comment := comments[0]
    vq := datastore.NewQuery("Vote").Filter("CommentKey=", keys[0])
    
    votes := make([]Vote, 0, 10)
    if _, err := vq.GetAll(c, &votes); err != nil {
        // handle the error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one typically implement a service layer in an MVC architecture? Is it
I would like to implement an distributed Point-Of-Sale system, somewhat like the one described
Similar to the one here on StackOverFlow, I would be needing to implement a
I'm trying to understand how to best implement a polymorphic one-to-many in hibernate. Eg:
Data in question would be mainly text with a one to many relationship (for
I have Plan table that has a one to many relationship with a Price
We implement an One-to-Many relationship by adding one Table's PK, as FK to the
I'm at a bit of a loss here. I have a one-to-many relationship between
I have developed one asp.net web application and now i would like to add
I want to implement one-to-many concept in my application. This is the scenario: I

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.