Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the entity with the newest date

Does anyone have any idea how to retrieve the last(with the newest date) entity in objectify? I know how to make a query but how to retrieve the one with the newest date?

List<Transaction> fetched2 = ofy.query(Transaction.class).filter("someproperty", somepropertyvalue).order("date").list();

I could try to bubble sort it but I´m sure there is an easier way. THX

like image 653
Bogdan Glosz Avatar asked May 16 '12 13:05

Bogdan Glosz


1 Answers

You just have to add a minus in front of "date" in your order :

List<Transaction> fetched2 = ofy.query(Transaction.class).filter("someproperty", somepropertyvalue).order("-date").list();

That should return you a list of Transaction with the newest one in first position.

like image 150
CMDej Avatar answered Sep 20 '22 13:09

CMDej