[appengine-java] datastore - order by query in a many to many model

2011-10-03 Thread gabriel munteanu
Hi,

I have the following model [pseudo code]:

db.Model(podcast, {
   name: StringProperty,
   description: TextProperty,
   homePageURL: StringProperty,
   addedDate: DateProperty
});

db.Model(category, {
   name: StringProperty,
   podcastsNumber: IntegerProperty
});

db.Model(podcastcategory, {
   category: ReferenceProperty({referenceClass: Category}),
   podcast: ReferenceProperty({referenceClass: Podcast})
});

I am trying to query the datastore to show in the web page the latest
5 podcasts in a certain category.

Problem is my approach seems very costly:

I do a query against podcastcategory and get al lentities there
filtered by my category property.
and i get all podcasts.
then I would have to sort them in my app by addedDate.

I feel that something is wrong, maybe my query or my data modelling. I
would appreciate any advice or links to set me to the right direction.

cheers,
Gabi

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] datastore - order by query in a many to many model

2011-10-03 Thread Ikai Lan (Google)
Hi Gabriel,

Ah, you're hitting the first bump in learning to think
non-relationally. Rather than creating 3 models, what about creating a List
of categories for each Podcast and just storing that on the podcast? The
tradeoff is that it won't be easy to rename a podcast category, but that
shouldn't be something that happens frequently.

When designing for the datastore, aim for designing for a key-value store
when possible, and don't think in terms of joins.

--
Ikai Lan
Developer Programs Engineer, Google App Engine
plus.ikailan.com | twitter.com/ikai



On Mon, Oct 3, 2011 at 2:30 AM, gabriel munteanu jajali...@gmail.comwrote:

 Hi,

 I have the following model [pseudo code]:

 db.Model(podcast, {
   name: StringProperty,
   description: TextProperty,
   homePageURL: StringProperty,
   addedDate: DateProperty
 });

 db.Model(category, {
   name: StringProperty,
   podcastsNumber: IntegerProperty
 });

 db.Model(podcastcategory, {
   category: ReferenceProperty({referenceClass: Category}),
   podcast: ReferenceProperty({referenceClass: Podcast})
 });

 I am trying to query the datastore to show in the web page the latest
 5 podcasts in a certain category.

 Problem is my approach seems very costly:

 I do a query against podcastcategory and get al lentities there
 filtered by my category property.
 and i get all podcasts.
 then I would have to sort them in my app by addedDate.

 I feel that something is wrong, maybe my query or my data modelling. I
 would appreciate any advice or links to set me to the right direction.

 cheers,
 Gabi

 --
 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
 google-appengine-java@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine-java+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/google-appengine-java?hl=en.



-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.