alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

Add explicit key query support to GAE DAL #159

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From mjwatson@gmail.com on January 19, 2011 22:46:10

Could we have some mechanism to support querying on an explicitly specified key via the GAE DAL. So we could use the DAL something like: ``` key = Key.from_path('A', 1, parent=Key.from_path('B', 2, parent=Key.from_path('C', 3, parent=Key.from_path('D', 4)))) model = db.A(db.A._gaeKey == key) <--- or something like this perhaps. ``` This is required as the key generated by GAE is composed of itself plus any parents it may have. ``` I.e. import google.appengine.ext.db as gae def txn() barry = Father(name='Barry') simon = Son(parent=barry, name='Simon') simon.put() barry.put() gae.run_in_tranaction(txn()) # assuming barry.id = 1, simon.id = 2 # to get Barry. barry = gae.get(Key.from_path('Father', 1)) # to get Simon (you need the parent key) simon = gae.get(Key.from_path('Simon', 2, parent=Key.from_path('Father', 1)) or simon = Son.get_by_id(2, parent=Key.from_path('Father', 1)) etc… etc… ``` _Original issue: http://code.google.com/p/web2py/issues/detail?id=161_
alfonsodg commented 10 years ago

From dly...@gmail.com on February 07, 2011 02:59:52

I have a private patch for the new DAL which will include the native GAE key in each row returned from the DAL. I do it by adding a last column with a special column name 'gaeRef' and then I patched the new DAL to store the native ref into that column. I made it the last column to maximize performance, so I don't have to search for it in the internal list.

alfonsodg commented 10 years ago

From mjwatson@gmail.com on March 03, 2011 02:11:37

http://groups.google.com/group/web2py/browse_thread/thread/7d31902bd092afcc/d21c0493c670edb6?lnk=gst&q=Keys#d21c0493c670edb6 Christian has provided a fix that has been tested by myself and works fine without altering the dal significantly.

Please refer to the last message on the above thread entitled Keys and GAE

alfonsodg commented 10 years ago

From massimo....@gmail.com on June 20, 2011 11:31:53

The patch linked was applied at the time.

Status: Fixed