本文介绍了SugarOrm:OrderBy相关表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有了SugarORM,我知道在一段恋情中我可以做到

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;
}

那我该如何在Book.class上进行查找,以便可以按作者排序.

How then can i do a find on Book.class such that i can order by authors.

我尝试过

Book.find(Book.class, null, null, null, "author.id desc",null);;

Book.find(Book.class, null, null, null, "author desc",null);;

所有这些都不起作用

推荐答案

对于简单查询,建议使用查询构建器方法,例如:

For a simple query it is recommended to use the query builder approach, for example:

Select.from(Book.class)
.orderBy("ISBN")
.list();

无论如何,请记住SugarORM是基于SQLite的,在您的特定情况下,您尝试按关系进行订购.然后,您应该使用联接构建自定义查询,并根据表Author的字段(ID,名称,姓氏等,取决于您的目的)按顺序排序

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)

这篇关于SugarOrm:OrderBy相关表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:56
查看更多