Thank you for re-thinking at the problem.
I had already denormalized, but I will use this below, ... the endless
capabilities of web2py ...
On Tuesday, October 2, 2012 3:33:39 AM UTC+9, Javier Pepe wrote:
>
> Hello
>
> You can create a function to represent in link
>
> links = [{'header':'Contador', 'body': lambda row: count_b(row.id) }]
>
>
> def count_b(a.id):
> c = db(db.B.ref_a == id).count()
> if c:
> count = c
> else:
> count = 0
> return count
>
> On Sun, Sep 30, 2012 at 9:26 AM, Massimo Di Pierro
> <[email protected]<javascript:>
> > wrote:
>
>> This is currently not possible unless you denormalize and store the count
>> in a column of A.
>>
>>
>> On Saturday, 29 September 2012 23:01:22 UTC-5, alex wrote:
>>>
>>>
>>> I have a relation [1:n] from table A to table B.
>>>
>>> define_table('A',
>>> Field('name', type='string'))
>>>
>>> define_table('B',
>>> Field('ref_a', type='reference A'))
>>>
>>>
>>>
>>> Then I have this grid
>>>
>>> qry = db.A.id>0
>>> grid = SQLFORM.grid(qry,links=links)
>>>
>>> How do I write links (and the lambda function in it) in order to have in
>>> the grid an additional column with the count of references to A
>>> (db.B.ref_a.count()) ?
>>>
>> --
>>
>>
>>
>>
>
>
--