Correction upon actually testing code in trunk: myParentNativeRef = myParent._last_reference # This uses Massimo's mod in the trunk...
should be: myParentNativeRef = myParent._table._last_reference # This uses Massimo's mod in the trunk... On Jun 27, 6:03 pm, dlypka <dly...@gmail.com> wrote: > # NOTE: I have *NOT* tested the following code > # because this is greatly simplified from my actual code, > # so some debugging may be necessary to get it to work > # > # The following assumes that gql.py has been modified to add a > statement to method > # insert(): > # add a new statemtent before the final return statement as > follows: > # self._last_reference = tmp # <==== Add this new statement, > as per Massimo's mod in the trunk ==== > # return rid > > # Here are the sample tables to create: > > db.define_table('ParentTable', > # NOTE: web2py provides the 'id' column > automatically > db.Field('name','text') > ) > > db.define_table('ChildTable', > # NOTE: web2py provides the 'id' column > automatically > db.Field('idParentFolder','reference > ParentTable'), > db.Field('age','integer'), > db.Field('name','text'), > db.Field('parentLink', > gae.ReferenceProperty(ParentTable, required=True, > collection_name='ChildCollection') # > native link to parent > ) > > # Here is the code to insert a parent and a child > > myParent = db.ParentTable.insert(name='Bill') > myParentNativeRef = myParent._last_reference # This uses > Massimo's mod in the trunk... > myParentid = myParent.id > > # NOTE: if myParentNativeRef is not available, then instead you > can > # use the technique in my previous forum msg to query for > the native ref and id of the Parent > > myChild = db.ChildTable.insert(age = 9, name = 'Johnny', > idParent = myParentid, > parentLink = myParentNativeRef) > > # -------- End of code to insert data > ------------------------------------------------------------ > > # > --------------------------------------------------------------------------- > ---------------------- > # Here is the code to retrieve the parent and children using the > native references > # Performance is very fast because GAE does this in a single call > to the Datastore: > > myParent = db(db.ParentTable.name=='Bill').select() # This is a > web2py query on steroids... > > for child in myParent.ChildCollection: > myChildName = child.name > myChildAge = child.age > > # ---------------------- End of Sample code > -------------------------------------------------------------------