Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
5881 Weergaven

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

Avatar
Annuleer
Beste antwoord

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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mei 24
2417
2
jun. 23
2660
1
jul. 24
1912
3
mei 24
3946
2
apr. 24
3858