# mybaseobject.subobject_set.all().filter(somefilter)
#[ all() is not a method of the Query class ]
mybaseobject.subobject_set.filter(somefilter)
# is equivalent too
SubObject.all().filter('baseref =', base).filter(somefilter)Is equivalent to my method because the referenced object (baseobject.subobject_set) constructs a Query that does the same thing as my line, only it does it based on the key. If you want to ref on some other property you have to write it yourself. From: http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html#References --------------------------------- ReferenceProperty has another handy feature: back-references. When a model has a ReferenceProperty to another model, each referenced entity gets a property whose value is a Query that returns all of the entities of the first model that refer to it. --------------------------------- 2009/6/6 mscwd01 <[email protected]>: > > I think your solution sounds the most elegant Tim... > > However, I am a little confused. So I would retrieve the desired > BaseObject and then how do I retrieve all the SubObjects that hold a > reference to it? Can you explain this bit: .subobject_set.all().filter > (somefilter) > > Thanks! > > On Jun 6, 1:26 am, Tim Hoffman <[email protected]> wrote: >> Even easier would be to have every subobject hold a reference to the >> parent BaseObject >> >> Then given any BaseObject you can >> >> mybaseobject.subobject_set.all().filter(somefilter) >> >> T >> >> On Jun 6, 7:27 am, djidjadji <[email protected]> wrote: >> >> > You can, do two calls to the datastore >> >> > # first get the required BaseObject >> > base = BaseObject.all().filter(.......).get() >> > if not base: return >> > # then get the SubObjects that link to this BaseObject with the right >> > fields >> > subobjs = SubObject.all().filter('baseref =', >> > base.reffield).filter('somefield >', subSelectValue).fetch(1000) >> > if not subobjs: return >> >> > 2009/6/5 mscwd01 <[email protected]>: >> >> > > So the relational model I mentioned would be the better option? >> >> > > Its a pity there isnt a feature to select desired baseObjects and then >> > > search within SubObjects linked to that object within a DataStore >> > > call... >> >> > > On Jun 5, 9:50 pm, djidjadji <[email protected]> wrote: >> > >> One huge object would be very inefficient. You have to retrieve the >> > >> whole lot every time you get() a BaseObject. You are limited to a >> > >> total size of 1 Mbyte per object. >> >> > >> Much cleaner is the approach with the two object Models. Now you can >> > >> have an unlimited number of SubObjects and let the index do most of >> > >> the work of fetching only the SubObjects that are important. >> >> > >> 2009/6/5 mscwd01 <[email protected]>: >> >> > >> > Hi, >> >> > >> > I have a question regarding the best method of storing a complex >> > >> > object which may grow to be very large in size. >> >> > >> > I have an object 'BaseObject' which has a field of type >> > >> > List<SubObject>. I wish to add many SubObject's to BaseObjects, >> > >> > perhaps millions. When querying a SubObject I will first retrieve the >> > >> > BaseObject and then perform a query on its list of SubObjects to find >> > >> > the objects I need. >> >> > >> > Now, is it a good idea to store objects in this way? I.e. having a >> > >> > BaseObject which comprises an enormous list of SubObjects? >> >> > >> > Another method of doing this would be to take the relational database >> > >> > approach and have a BaseObject and SubObjects table where SubObjects >> > >> > reference BaseObjects via an ID. However, I would really like to >> > >> > maintain an object approach. >> >> > >> > What are your views on this? Any feedback would be greatly >> > >> > appreciated. >> >> > >> > Thanks > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" 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?hl=en -~----------~----~----~----~------~----~------~--~---
