コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6022 ビュー

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

アバター
破棄
最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
1
5月 24
2555
2
6月 23
2836
1
7月 24
2080
3
5月 24
4131
2
4月 24
4105