Sorry that should have been: a = db(db.A.id == ['A:1', 'B:2', 'C:3', ''D:4')
Matt On Jan 11, 4:39 pm, Matt <[email protected]> wrote: > Thanks Christian, > > Your suggestion looks good. > > Could potentially specify the "tablename" like: > > db(db.address.id == ['user:21', 'address:96']) > > NB: this would need to support full recurvsive key generation so that > you could specify: > > Assuming: > > C.parent = D.id = 4 > B.parent = C.id = 3 > A.parent = B.id = 2 > A.id = 1 > > And have the key generated as: > > key = Key.from_path('A', 1, parent=Key.from_path('B', 2, > parent=Key.from_path('C', 3, parent=Key.from_path('D', 4)))) > > Which would equate to: > > a = db(db.A.id == ['D:4', 'C:3', 'B:2', 'A:1']) > > Matt > > On Jan 11, 3:48 pm, Christian Foster Howes <[email protected]> wrote: > > > > > > > > > Matt, > > > so now i understand completely. thanks for the clarification. > > > this may be crazy talk, so hopefully those closer to the DAL will weigh > > in here, but take a look at line select_raw of dal.py (i don't have a > > line number since i have all modified versions, it's around 2670): > > > elif filter.name=='__key__' and filter.op=='=': > > if filter.value==0: > > items = [] > > else: > > item = tableobj.get_by_id(filter.value) > > items = (item and [item]) or [] > > > here is where the db(db.address.id == 42) gets put together. I'm making > > the assumption you would only do == queries, and that you might like > > something this for your query: > > db(db.address.id == [<parent_obj>, <this_id>] > > > which gets put into the dal code block like: > > > elif filter.name=='__key__' and filter.op=='=': > > if filter.value==0: > > items = [] > > if isinstance(filter.value, list): > > key = Key.from_path(filter.value[0].tablename, #get > > table name here somehow > > filter.value[0].id, > > tablename, filter.value[1], > > else: > > item = tableobj.get_by_id(filter.value) > > items = (item and [item]) or [] > > > NOTE: i have not tested or even run this code. just a suggestion on > > what it might look like. > > > there is also this > > thread:https://groups.google.com/forum/#!topic/web2py/WNDXVNNUyQ8 but it > > does > > not model parents quite like GAE would by default. > > > cfh > > > On 01/10/2011 06:21 PM, Matt wrote: > > > > Hi Christian, > > > > Thanks for your response. > > > > In order to save my entities (as part of an entity group) I've had to > > > set the parent of the 'address' to be the 'user'. That way I can use a > > > transaction to persist these multiple entities in one go. > > > > I.e. assuming: > > > > db.define_table('user', > > > db.Field('name', 'string')) > > > > db.define_table('address', > > > db.Field('street', 'string')) > > > > In my code (more or less): > > > > from google.appengine.ext import db as gae > > > > def txn(name, street): > > > user = db.user._tableobj(name=name) > > > address = db.address._tableobj(parent=user, street=street) > > > user.put() > > > address.put() > > > > gae.run_in_transaction(txn, name='Barry', street='Whatever') > > > > Now since I've used a parent for the address I can't do queries using > > > the DAL like: > > > > address = db.address(addressId) > > > > or > > > > address = db.address(db.address.id == addressId) etc. > > > > As it always returns None as the "key" for this entity is now composed > > > of itself plus it's parent. Which I have no way to specify. > > > > So hence I have to step outside of web2py to retrieve records using > > > raw GQL calls and means that I lose nice web2py features like: > > > > Inside my html: > > > > {{= address.user.name }} > > > > Does that make sense? > > > > Ideally I'd like to be able to construct the key and compare it like > > > any other field. > > > > Perhaps a custom GAE method to support this could be added to the > > > core? > > > > Cheers, > > > Matt > > > > On Jan 11, 12:55 pm, howesc<[email protected]> wrote: > > >> I must admit i'm not following your example. why do you need to query by > > >> GAE __key__ rather than by ID? (i have not used ancestors in GAE so > > >> maybe > > >> that is why i'm mis-understanding). > > > >> but your reference to my previous exchange made me look at this in the > > >> new > > >> DAL - and the !=,<,>,<=, and>= queries are broken again on GAE. I'll > > >> work on putting a patch together for that since i did it before. if you > > >> help me understand your problem better perhaps i can help get you the > > >> solution that you need. > > > >> thanks, > > > >> christian

