How about this?

def grid():
    form = SQLFORM.grid(db.thing_a, links=[lambda row: A('b things', 
_href=URL('grid_b',args=row.id))])
    return locals()

def grid_b():
    a_id = request.args(0) 
    query = (db.thing_b.id==db.join_table.b_id) & (db.join_table.a_id==a_id)
    filelds = columns = [f for f in db.thing_b if f.readable and f.listable]
    form = SQLFORM.grid(query, fields=fields, args=[a_id])
    return locals()


On Sunday, 2 September 2018 11:03:30 UTC-7, [email protected] wrote:
>
> Hi,
>
> the amount of googling I've fruitlessly put into this problem might 
> indicate that it's either a really remote corner case or something so 
> obvious that I'm the only one missing it.
>
> The problem:
> I've multiple many-to-many relations in my app, and I'm building a simple 
> management interface for few select users. It looks like smartgrid would be 
> perfect and astoundingly convenient solution for the problem, but it seems 
> to struggle with linking the objects joined via the join table. It seems to 
> selectively work in cases where the object to link to is directly referred 
> to by something else in the tree or otherwise 'known'.
>
> I've put together simplest possible case that seems to reproduce this 
> issue:
>
> models/db1.py:
> # simple helper to populate simple relation
> def populate():
>     a = db.thing_a.insert(a_thing='foo')
>     b = db.thing_b.insert(b_thing='bar')
>     db.join_table.insert(a_id=a.id,
>                          b_id=b.id)
>
> db.define_table('thing_a', Field('a_thing'))
> db.define_table('thing_b', Field('b_thing'))
> db.define_table('join_table',
>                 Field('a_id', db.thing_a),
>                 Field('b_id', db.thing_b))
>
> populate()
>
> controllers/things.py:
> def grid():
>     form = SQLFORM.smartgrid(db.thing_a)
>     return locals()
>
> Now, going to http://127.0.0.1:8000/{app_name}/things/grid shows the 
> thing_a and there's a link to the join table, but the join table view links 
> only to thing_a, not thing_b. Relation to thing_b is shown fine and the 
> records can be inserted, edited and deleted just fine, but the lack of link 
> to thing_b is what breaks it for my purpose. This issue seems to be present 
> even in the example of "very powerful management interface" shown in the 
> book (applied to this same example).
>
> I could circumvent the issue by showing only the links to direct 
> references and manually adding links to join table ones, but it feels a bit 
> wrong when there's something so ready and close already available.
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to