Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
5386 มุมมอง

I want to use sql queries in CustomerPortal class controllers. I wrote following code:

request.cr.execute("""my query""")
result = request.cr.fetchall()
but I get the following error:
AttributeError: 'CustomerPortal (extended by PortalAccount, Custome' object has no attribute 'cr'a
what should I do?
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Arian, try to use 'request.session.cr' instead of 'request.cr'.


อวตาร
ละทิ้ง
ผู้เขียน

thanks! request.env.cr worked for me aswell.

คำตอบที่ดีที่สุด

https://github.com/odoo/odoo/blob/13.0/addons/web/controllers/main.py#L1551

## inside try

registry = odoo.modules.registry.Registry(dbname)
with registry.cursor() as cr:
cr.execute(""" query """)
row = cr.fetchone()
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
พ.ค. 20
12818
3
ต.ค. 15
6587
2
ก.ค. 25
1513
1
พ.ค. 24
2768
2
ก.พ. 24
2241