Assuming you have try: from gluon.contrib.gql import * # if running on Google App Engine except: db=SQLDB('sqlite://storage.db') # if not, use SQLite or other DB - Used by T2 datastoretype = 'SQL' else: db=GQLDB() # connect to Googl datastoretype = 'GAE'
# So now, db is the GAE db # To use those Collections in the Reference properites, you need to insert NATIVE GAE references, # so you need to somehow find the GAE entity instance reference given a web2py sql row # Here is the 'Stargate / wormhole' code which takes you from web2py back down into the native GAE Datastore alternate universe: # So if you have a web2py table name 'ChildTable': web2pyChildTableClass = db.ChildTable # gives the web2py Table class theNativeGAEChildTableClass = web2pyChildTableClass._tableobj # magic... into GAE # ================================================================ # Now do a native GAE query to find the native GAE instance so it # can be put into the Reference collection: nativeGAE ChildTableQuery = theNativeGAEChildTableClass.all() nativeGAEChildTableQuery.filter('id =', 25) # get for id = 25 nativeresults = nativeGAEChildTableQuery.fetch(limit=1) myGAENativeChild = nativeresults[0] # Now myGAENativeChild can be inserted into the native GAE Reference collection - Dave Lypka On Jun 26, 5:48 am, Carles Gonzalez <carle...@gmail.com> wrote: > Very interesting, i didn't know about collection_name and the associated > query. > > You are shedding some light on doing relationships the GAE way. > > Thanks again. > > > > On Sat, Jun 26, 2010 at 8:52 AM, dlypka <dly...@gmail.com> wrote: > > > For starters: > > > Refer to > >http://arbingersys.blogspot.com/2008/04/google-app-engine-one-to-many... > > > And Here is the posting about using native GAE properties > > >http://groups.google.com/group/web2py/browse_thread/thread/7112ef7dee... > > > So for example you would do > > > from gluon.contrib.gql import gae > > : > > : > > db.define_table('ChildItem', > > # NOTE: web2py provides the 'id' > > column automatically > > db.Field('idParentFolder','reference > > MyParent'), > > db.Field('name','text'), > > db.Field('gaeParentInstance', > > gae.ReferenceProperty(MyParent, > > required=False, > > collection_name='linksFromChildItemToParent'))) > > > ) > > > and define the parent class in a similar fashion. > > > It is also necessary to add some plumbing to find and track the native > > GAE references > > which lie underneath the web2py sql objects because the native refs > > have to be > > put into the collections. > > > I'll provide more details in some followup posts. > > > On Jun 25, 2:48 pm, Carles <carle...@gmail.com> wrote: > >> Thanks a lot Dave. > > >> There isn't a deadline, tale your time :) > > >> Carles > > >> El 25/06/2010, a las 20:42, dlypka <dly...@gmail.com> escribió: > > >> > OK will do - please give me a few days... > > >> > On Jun 24, 8:43 pm, Carles Gonzalez <carle...@gmail.com> wrote: > >> >> Not to be annoying, but can you post an example? > > >> >> Just to organize the things in my head... > > >> >> Thanks again. > > >> >> On Fri, Jun 25, 2010 at 2:41 AM, Carles Gonzalez <carle...@gmail.com> > >> >> wrote: > >> >>> Very interesting! > > >> >>> I'll try tomorrow. > > >> >>> Thanks a lot, Dave. > > >> >>> On Fri, Jun 25, 2010 at 1:21 AM, dlypka <dly...@gmail.com> wrote: > >> >>>> I've done a parent - to - many child GAE / web2py implementation using > >> >>>> SelfReference fields (or you can use Reference as well) using the > >> >>>> technique for adding native GAE fields into a web2py table definition. > > >> >>>> It gives fantastic retrieval performance because GAE automatically > >> >>>> adds the link from the child back into the parent's reference list > >> >>>> at the time you create each child. When you later query for the > >> >>>> parent, voila GAE retrieves all the child entities along with it in > >> >>>> one backend call! > > >> >>>> Hopefully this technique is relevant to your application. > > >> >>>> I also develop some other tricks for inheriting native GAE classes > >> >>>> into your web2py model, though > >> >>>> this is less attractive perhaps now that GAE native properties can be > >> >>>> directly declared in web2py tables. > > >> >>>> - Dave Lypka. > > >> >>>> On Jun 21, 10:25 am, Carles Gonzalez <carle...@gmail.com> wrote: > >> >>>>> Hi, > > >> >>>>> I have developed some applications in web2py, and 2 are running > >> >>>>> currently in gae, but now i have serious problem. > > >> >>>>> My current project is a social application, and when i design > >> >>>>> (example) the tables to make an user follow the actions other user > >> >>>>> (twitter like) I find that many-to-many relationships in app-engine > >> >>>>> are not easily supported. > > >> >>>>> From my understanding using the tools present in web2py right i would > >> >>>>> need to do a lot of processing in memory, an that would hurt > >> >>>>> performance greatly. > > >> >>>>> The pattern proposed by app store developers uses lists and "parent" > >> >>>>> relationship: > > >> >>>>> class Message(db.Model): > >> >>>>> sender = db.StringProperty() > >> >>>>> body = db.TextProperty() > > >> >>>>> class MessageIndex(db.Model): > >> >>>>> receivers = db.StringListProperty() > > >> >>>>> indexes = MessageIndex.all(keys_only = True).filter('receivers = ', > >> >>>>> user_id) > >> >>>>> keys = [k.parent() for k in indexes) > >> >>>>> messages = db.get(keys) > > >> >>>>> For using that pattern in web2py I would need a method for specifying > >> >>>>> the parent of a model instance. Can I specify that relationship using > >> >>>>> any method I don't know? If not, would it be hard to implement? > > >> >>>>> Thanks in advance!