represent=lambda value, row: db.customers_company(value).company_name if
value is not None and value != '' else T('N/A')Or format='%(company_name)s' on customers_comapny table at the end of you define_table. Richard If you want to search the company name, you have to pass a query to SQLFORM.grid instead of using represent... Since with represent SQLFROM.grid still use the id to reference the other table and you can't search the referenced field. See this thread : https://groups.google.com/d/msg/web2py/wUBbAzFHbxs/5k4FDYmyfcQJ Richard On Thu, Jul 25, 2013 at 5:33 AM, David Marko <[email protected]> wrote: > I have a simple 1:N relation (I think its very common scenatio) as you can > see below. Now how can I create a query form SQLFORM.grid to show > 'customer_person' table but view company_name in 'company' column instead > of ID? I tried to put this query to grid 'db_companies.id == > db_persons.company ' (inner join), it worked nice but 'show' button from > grid viewed the 'customers_company' and not the 'customers_person' table. > Is there a way how to accomplish this using e.g. left join? > > > db_companies=db.define_table('customers_company', > Field('company_name','string'), > Field('city','string',label=T('Město')), > ) > > db.define_table('customers_person', > Field('company','reference customers_company', requires= > IS_IN_DB(db,"customers_company.id","customers_company.company_name")), > Field('firstname','string'), > Field('lastname','string'), > ) > > -- > > --- > 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/groups/opt_out. > > > -- --- 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/groups/opt_out.

