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

Hello, 

public_user = self.env.ref('base.public_user')
public_book = self.env['library.book'].with_user(public_user)
public_book.search([('name', 'ilike', 'cookbook')])

i want to ask that why we use with_user() and public_user what is the advantage of using this. can someone please explain . thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi, 

with_user(user) function return a new version of this record set attached to the given user,
in non-superuser mode, unless `user` is the superuser (by convention, the superuser is always in superuser mode.

In your code,

public_user = self.env.ref('base.public_user')
public_book = self.env['library.book'].with_user(public_user)
It means environment of the model "library.book" will be opened with the user permission as of a public user.

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 24
2470
2
thg 6 23
2724
1
thg 7 24
1972
3
thg 5 24
4022
2
thg 4 24
3939