Selecting from SQLFORM grid generated using a join selects incorrect IDs

29 views
Skip to first unread message

Francis Windram

unread,
Nov 19, 2018, 4:48:14 AM11/19/18
to web2py-users
Hi All,

I'm hitting an issue with the selectable field in SQLFORM.grid.

I have a controller including a grid generated from a join on three tables as follows:

applics_fields = ['first_name', 'last_name', 'email', 'rank', 'nerc_elig', 'cv', 'coverletter', 'refletter1',
                     
'refletter2']
    proposals_fields
= ['project_title', 'case_partner']
    pi_fields
= ['first_name', 'last_name']
    fields_to_select
= [db.applics1[field] for field in applics_fields] + \
                       
[db.proposals[field] for field in proposals_fields] + \
                       
[db.PIs[field] for field in pi_fields]

    grid
= SQLFORM.grid((db.applics1.project == db.proposals.id) & (db.proposals.PI_name == db.PIs.id),
                        csv
=False,
                        deletable
=False,
                        create
=False,
                        details
=False,
                        editable
=False,
                        fields
=fields_to_select,
                        headers
={'PIs.last_name': 'PI Last Name', 'PIs.first_name': 'PI First Name'},
                        selectable
=[('Download Public PDFs', lambda ids: zip_pdfs(ids, track=1))],
                        paginate
=False)

This generates the correct grid in the view, however when I select the records I want to pass to zip_pdfs(), the ids passed to the function are those of the PI table, not of the applics1 table.

Is there a way to specify from which table it pulls the ids to be selected and passed to zip_pdfs()?

Thanks,
Francis

Anthony

unread,
Nov 19, 2018, 9:38:55 AM11/19/18
to web2py-users
With joins, you have to specify the ID field explicitly:

SQLFORM.grid(..., field_id=db.applics1.id)

Anthony

Francis Windram

unread,
Nov 19, 2018, 10:27:30 AM11/19/18
to web...@googlegroups.com

That works perfectly! Thank you very much
Reply all
Reply to author
Forward
0 new messages