SQLFORM.grid links and inner join

275 views
Skip to first unread message

Louis Amon

unread,
Aug 28, 2014, 11:04:36 AM8/28/14
to web...@googlegroups.com

I have a simple one-to-many relation like so:

db.define_table('person', Field('job'))
db
.define_table('thing', Field('owner_id', 'reference person'))

And I built a grid using SQLFORM.grid like so:
grid = SQLFORM.grid((db.person.id == db.thing.owner_id),
                    fields
=[db.thing.owner_id, db.person.job],
                    links
=[dict(header='Details for thing',
                                body
=thing_link)
                         
],
                   
)

With the function thing_link defined like this:
def thing_link(row):
   
print row
   
return A('controller', 'function', args=[row.thing.uuid])


I get a ticket when loading the grid, and as far as I can tell looking at the print in thing_link, the row passed in the body of the link does not contain both tables of the inner join : it only contains whichever comes first (so row.person in this case, in terms or alphabetical order).

Is there a way around this ?

Louis Amon

unread,
Aug 28, 2014, 11:08:50 AM8/28/14
to web...@googlegroups.com
Actually, if I look at the View, Edit and Delete buttons generated by the grid, it seems that in the case of a simple query the grid knows which table to use,
but in the case of an inner join it arbitrarily selects the first table as the "main table" and generates links and buttons accordingly.
Reply all
Reply to author
Forward
0 new messages