comparison between foreign key id and name

21 views
Skip to first unread message

yogeshwar khalkar

unread,
Jan 16, 2018, 4:55:13 AM1/16/18
to web2py-users

Hi,

Please help me with following.

I have created the api  I am passing company_name(string) to it, for select I am comparing reference Id to name.
I get the error 

<type 'exceptions.ValueError'> invalid literal for long() with base 10: 'cadence'

at db.company_user.company == company_name
I actually don't know how to compare reference id to name.
 

@request.restful()
def company_user():
def GET(company_name, role=None):
company_user_ids = [u['auth_user'] for u in db(db.company_user.company == company_name
).select()]
query = db.auth_user.id.belongs(company_user_ids)
auth_users = db(query).select(db.auth_user.ALL)
return json(auth_users)
return locals()

Thanks.

Anthony

unread,
Jan 16, 2018, 10:37:41 AM1/16/18
to web2py-users
DAL reference fields store the record ID of the linked record, not the value of one of its other fields. So, you comparison must be to the record ID of the company, not the company name.

Anthony
Reply all
Reply to author
Forward
0 new messages