Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5350 Lượt xem

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?
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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()
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 5 20
12774
3
thg 10 15
6572
2
thg 7 25
1415
1
thg 5 24
2713
2
thg 2 24
2196