On Saturday, February 2, 2013 2:07:15 AM UTC+1, 黄祥 wrote: > > thank you so much for your hints niphlod. > yes you re right that i want is "all data of the company the current user > belongs to" > actually i've just modified your hints and works well > > def invoice(): > query=db(db.sale.invoice_no==request.args(0)).select().first() > row=db((db.company.id==db.auth_user.company_id)& > (query.created_by==db.auth_user.id)).select().first() > invoices=db(db.sale.invoice_no==request.args(0)).select() > return dict(query=query, row=row, invoices=invoices) > > how do you think? >
I really think that your requirements don't match those queries... you fetch a single db.sale line right in the first statement. Then, "row" takes presumably the company from the user who created the invoice Then another identical query for assigning "invoices" to more or less the same thing of "query" Wasn't the purpose of the thread to fetch all the data (company, invoices, etc) of the current user ? > i'm just still confuse the relation between > company_id = db(db.auth_user.id == > auth.user_id).select().first().company_id > company_id is the "integer" referencing your company inside the auth_user table. All users belonging to a company have the same integer in the company_id column. The previous query broken to pieces is db(db.auth_user.id == auth.user_id) ##auth.user_id is the id of the currently logged-in user, or none if the user isn't logged. .select().first() ## retrieve the record of the user from the auth_user table .company_id ##retrieve the value stored into the company_id column > and > db.auth_user.company_id == company_id > > This fetches all the users belonging to the same company (i.e. given a company_id = 3, all the rows in the auth_user table that have the company_id column == 3) -- --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.