Skip to Content
Menu
This question has been flagged
1 Reply
13316 Views

Hello,

I want to find a records according to search method. These records should satisfy 2 criterias.

Can i use the search method as follows : 

rec = self.env['Module.class1'].search(['&',('id', '=', self.id),('pid','=',self.pid)])
Avatar
Discard
Best Answer

Hi Zak,

You can do it like this ,

rec = self.env['Module.class1'].search([('id', '=', self.id),('pid','=',self.pid)])


Thanks

Avatar
Discard
Author

Thank you Niyas, Search return a list of records, how i can get only one record ?

Search method returns all those records which satisfies the given criteria, you can use a for loop and can iterate it like this,

search_rec = self.env['Module.class1'].search([('id', '=', self.id),('pid','=',self.pid)])

for rec in search_rec:

print rec

Author

You can't directly get a record without using for ?

Try like this,

rec = self.env['Module.class1'].search([('id', '=', self.id),('pid','=',self.pid), limit=1])

Try like this,

rec = self.env['Module.class1'].search([('id', '=', self.id),('pid','=',self.pid)], limit=1)

Author

Thank you sir