Reputation: 539
I want to access data of two latest records of a model using ORM API's record.search()
method in Odoo 9. Is it possible to get the data of two latest records based on the value of create date field in a model? This is the code I am going to get the latest records with it:
@api.multi
def get_data(self, rec):
reference_data = self.env['recuite.reference.reference'].search([('recruite_id', '=', rec.id)])
What parameter should I add to search method to get intended result?
Upvotes: 1
Views: 4477
Reputation: 26718
You need to add two arguments to the search method:
, order='create_date desc', limit=2)
Parametersint
) -- number of results to ignore (default: none)int
) -- maximum number of records to return (default: all)str
) -- sort stringbool
) -- if True, only counts and returns the number of matching records (default: False)limit
records matching the search criteriaUpvotes: 5