# I believe the new '_last_reference' property still needs a
'nativeRef' type
# added to web2py in order to take full advantage of it:
#
# For running web2py on Google App Engine:
# I coded and successfully tested a GAE-specific proof of concept as
follows:
db.define_table('ParentTable',
# NOTE: web2py provides the 'id' column automatically
db.Field('name','string', length=50), # NOTE! for GAE you must
specify 'string', not 'text'!!
db.Field('gaeRef', gae.ReferenceProperty())
# See
http://www.mail-archive.com/[email protected]/msg05177.html
)
db.define_table('ChildTable',
# NOTE: web2py provides the 'id' column automatically
db.Field('idParent','reference ParentTable'),
db.Field('age','integer'),
db.Field('name','string', length=50), # NOTE! for GAE you must
specify 'string', not 'text'!!
db.Field('parentLink',
gae.ReferenceProperty(db.ParentTable._tableobj, required=True,
collection_name='ChildCollection')),
db.Field('gaeRef', gae.ReferenceProperty())
)
# To support this, I patched gql.py around line 700 in method
'select':
def select(self, *fields, **attributes):
:
:
rows = []
lastField = fields[len(fields)-1] # dlypka
for item in items:
new_item = []
for t in fields:
if t == 'id':
new_item.append(int(item.key().id()))
else:
new_item.append(getattr(item, t))
if lastField == 'gaeRef': # dlypka
new_item[len(new_item)-1] = item # dlypka
rows.append(new_item)
colnames = ['%s.%s' % (tablename, t) for t in fields]
#
----------------------------------------------------------------------------------------
# Proposal:
# In place of this patch, I would prefer that web2py add a new field
type
# named 'nativeRef', and gql.py method 'select' should store the
value of 'item' in such columns.
# With the 'nativeRef' type added to web2py, the proof of concept
would be as follows:
db.define_table('ParentTable',
db.Field('name','string', length=50), # NOTE! for GAE you
must
specify 'string', not 'text'!!
db.Field('gaeRef', 'nativeRef')
)
db.define_table('ChildTable',
db.Field('idParent','reference ParentTable'),
db.Field('age','integer'),
db.Field('name','string', length=50), # NOTE! for GAE you
must
specify 'string', not 'text'!!
db.Field('parentLink',
gae.ReferenceProperty(db.ParentTable._tableobj, required=True,
collection_name='ChildCollection')),
db.Field('gaeRef', 'nativeRef')
)
myParent = db.ParentTable.insert(name='Bill')
myChild = db.ChildTable.insert(idParent = myParentid.id,
age = 9,
name = 'Johnny',
parentLink =
myParent._table._last_reference)
# Later, you can use web2py queries mixed with a native GAE
Reference to find the children
# with very high performance because the chidren are retrieved in
the parent query:
rows = db(db.ParentTable.name == 'Bill' ).select()
myParentFromQuery = rows[0]
for child in myParentFromQuery.gaeRef.ChildCollection:
myChildName = child.name
myChildAge = child.age
# ----------------- End of Proof of Concept
-----------------------------------------