How can I leave one record (last/newest) for each resource_owner_id and scopes combination and remove other records?
For example, for resource_owner_id=3 and scopes=driver it should be only record with id=1357.resource_owner_id=5 and scopes=driver - with id=1034
I know that I can use .ids
, after that get all records by id and scope (scopes are enum - 'driver' and 'passenger'), after that use .pop
and remove all remaining records.
Maybe there is a more elegant solution?