I have a two tables, one of which references the other. I would like to 
create a complex query involving those two tables, and pass this query to 
an SQLFORM.grid() to view entries in the first table. 

Basically, I'd like the grid to show table1 entries which meet some 
preliminary set of conditions (pertaining to fields in table1), and which 
either have a null reference to table2, or which have a reference to table2 
and for that reference, the value of a particular field in table2 is equal 
to True. The current setup is something like this:

db.define_table('table1',
    Field('ref_to_table2', type = 'reference table2'),
    ...)
    
db.define_table('table2',
    Field('condition', type = 'boolean'),
    ...)
    
query_list = [...]   # list of queries
query_additional = ((db.table1.ref_to_table2 == None) | 
((db.table1.ref_to_table2 
!= None) & (db.table2.condition == True)))
query_list.append(query_additional)
query = reduce_query_list(query_list)
...
grid = SQLFORM.grid(query, fields = [list_of_table1_fields])

As a result of including the reference to table2, feeding 'query' to 
SQLFORM.grid() produces the error, "<type 'exceptions.AttributeError'> 
'Row' object has no attribute 'id'". Any suggestions on how to achieve the 
desired result (this function will be called frequently, so efficiency is 
important)? Thank you.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to