Ahhh . . . now I just feel silly! Thanks.

Ian

On Thursday, March 15, 2012 4:57:58 PM UTC-4, rochacbruno wrote:
>
> You cannot perform a query to a Virtual Field, queries run on database 
> level, virtual fields runs on app level.
>
> You can just fetch a subset of rows then use .find() to fiter that rows.
>
> On Thu, Mar 15, 2012 at 5:55 PM, monotasker wrote:
>
>> I had a nice query set up and working that looked for any match between 
>> items in a list and records in a list-reference field:
>>
>> catXtags = [2,4,6,7,9]
>> curr_loc.id = 6
>>
>>     db((db.paths.tags.contains(catXtags)) & (db.paths.locations.contains(
>> curr_loc.id))
>>
>> I changed db.paths.tags to be a virtual field that constructs the same 
>> list of foreign id's dynamically. But now when I run the query I get this 
>> error:
>>
>> <type 'exceptions.KeyError'> 'tags'
>> The weird thing is that when I print db.paths.tags in the preceding line 
>> I get a nice list of integers. So the key 'tags' does seem to exist in 
>> db.paths.fields and the data should be the right format. I'm really not 
>> sure what I'm doing wrong!
>>
>> Any help is much appreciated. For reference, the full error traceback is 
>> below.
>>
>> Traceback (most recent call last):
>>   File "/home/ian/web/web2py/gluon/restricted.py", line 204, in restricted
>>
>>
>>     exec ccode in environment
>>   File "/home/ian/web/web2py/applications/paideia/controllers/exploring.py" 
>> <http://127.0.0.1:8000/admin/default/edit/paideia/controllers/exploring.py>, 
>> line 104, in <module>
>>
>>
>>   File "/home/ian/web/web2py/gluon/globals.py", line 172, in <lambda>
>>
>>
>>     self._caller = lambda f: f()
>>
>>
>>   File "/home/ian/web/web2py/gluon/tools.py", line 2533, in f
>>
>>
>>     return action(*a, **b)
>>   File "/home/ian/web/web2py/applications/paideia/controllers/exploring.py" 
>> <http://127.0.0.1:8000/admin/default/edit/paideia/controllers/exploring.py>, 
>> line 95, in index
>>
>>
>>     return step_init()
>>   File "/home/ian/web/web2py/applications/paideia/controllers/exploring.py" 
>> <http://127.0.0.1:8000/admin/default/edit/paideia/controllers/exploring.py>, 
>> line 21, in step_init
>>
>>
>>     path_result = path.pick()
>>   File "applications/paideia/modules/paideia_exploring.py", line 196, in pick
>>
>>
>>     p = self.find_paths(cat, curr_loc)
>>
>>
>>   File "applications/paideia/modules/paideia_exploring.py", line 232, in 
>> find_paths
>>
>>
>>     catXpaths = db((db.paths.tags.contains(catXtags))
>>
>>
>>   File "/home/ian/web/web2py/gluon/dal.py", line 5542, in __getattr__
>>
>>
>>     return self[key]
>>   File "/home/ian/web/web2py/gluon/dal.py", line 5482, in __getitem__
>>
>>
>>     return dict.__getitem__(self, str(key))
>>
>> KeyError: 'tags'
>>
>>
>>
>
>
> -- 
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

Reply via email to