This is not the way that I would do it. First, this is the JAVA app
engine group that code looks like python as is the link you
referenced. The way I have found in app engine to be able to make
the fastest queries is to use lists of keys in each object to manage
relationships.
so your model would look like this.
USER has a list of URL's and a URL has a list of USER's
This way you can find all the URL's of a user by
Query query = pm.newQuery(URL.class);
query.setFilter("userId == userParam");
query.declareParameters("Key userParam");
query.declareImport("import com.google.appengine.api.datastore.Key" );
List<URL> myURLs = (List<URL>) query.execute(userId);
Or find all the USER's that hold a URL
Query query = pm.newQuery(USER.class);
query.setFilter("urlId == urlParam");
query.declareParameters("Key urlParam");
query.declareImport("import com.google.appengine.api.datastore.Key" );
List<USER> urlUsers = (List<USER>) query.execute(urlId);
I usually put this in a static function in my class
public static USER getUserFromURL(urlId)
Same goes for URL's and TAG's
What then do you have to worry about. When a user removes a URL you
have to remove it from the USER and the URL. This means more work
when a change happens but reads happen much more often than writes(a
mind set you need to accept to work on app engine) so we optimize for
the reads not the writes.
Watch this google IO lecture to see even more about this including
ways to handle your user having 2000+ URL's
http://www.google.com/events/io/2009/sessions/BuildingScalableComplexApps.html
If you have any other questions, feel free to ask.
On Jan 18, 6:57 am, Ben Carlson <[email protected]> wrote:
> Hello, I'm writing a replacement for del.icio.us on GAE, and am really
> struggling with what the right way to do the User / URL / Tag
> relationship:
>
> Here's what I'm referencing for my idea:
>
> http://code.google.com/appengine/articles/modeling.html
>
> My thought is to have three Entity's:
>
> User
> URL
> Tag
>
> Then use a relationship model for the inter-relationships:
>
> class UserURLTags(db.Model):
> userURLs = db.ReferenceProperty(User,
> required=True,
> collection_name='urls')
> userTags = db.ReferenceProperty(User,
> required=True,
> collection_name='tags')
> urlUsers = db.ReferenceProperty(URL,
> required=True,
> collection_name='users')
> urlTags = db.ReferenceProperty(URL,
> required=True,
> collection_name='tags')
> tagUsers = db.ReferenceProperty(Tag,
> required=True,
> collection_name='users')
> tagURLs = db.ReferenceProperty(Tag,
> required=True,
> collection_name='urls')
>
> The idea behind this is to allow lookups for each of the following:
>
> User's URLs (get all of user xyz's URLs)
> User's Tags
>
> URL's Tags (get all of the tags for URL 'abc')
> URL's Users
>
> Tag's URLs (get all of the URLs tagged with 'efg')
> Tag's Users
>
> Is this just a terrible mis-understanding of the proper way of doing
> this association?
>
> Thanks in advance!
>
> -Ben
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.