With SugarORM , I understand in a relationship I can do this
public class Book extends SugarRecord<Book> {
String name;
String ISBN;
String title;
String shortSummary;
// defining a relationship
Author author;
}
How then can i do a find on Book.class such that i can order by authors.
I have tried
Book.find(Book.class, null, null, null, "author.id desc",null);;
and
Book.find(Book.class, null, null, null, "author desc",null);;
and all these wont work
For a simple query it is recommended to use the query builder approach, for example:
Select.from(Book.class)
.orderBy("ISBN")
.list();
Anyway remember that SugarORM is based on SQLite and in your specific case you are trying to order by a relationship. Then you should build a custom query with a join, and the order by a field of the table Author (id, name, surname, etc...depending on your purpose)
My suggestion is that you use Sugar ORM Custom Query Builder
, which can be called by using this
Book.executeQuery("VACUUM");
Or you can also use method findWithQuery
with the following syntax
List<Note> notes = Note.findWithQuery(Note.class, "SELECT * FROM Book
ORDER BY author DESC", null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With