Android。解析。多对多使用数组

Android. Parse. Many-to-many using an array

the official documentation 中的示例显示了如何在 Array 类型的列中查找 ParseObject

// set up our query for the Book object
ParseQuery bookQuery = ParseQuery.getQuery("Book");

// configure any constraints on your query...
booKQuery.whereEqualTo("authors", author);

// tell the query to fetch all of the Author objects along with the Book
bookQuery.include("authors");

// execute the query
bookQuery.findInBackground(newFindCallback<ParseObject>() {
    public void done(List<ParseObject> bookList, ParseException e) {

    }
});

我的问题是:有没有一种方法可以使用多个 "author" ParseObject 而不是一个?我正在尝试搜索 Array 中的对象,这些对象包含在另一个查询的结果中。

更准确地说:我想获得所有名字以 "xxxx" 开头的作者所写的所有书籍。并在单个查询中执行此操作。

甚至可以在单个查询中完成吗?! 如果我执行 booKQuery.whereMatchesQuery("authors", innerQuery); where innerQuery 查询 Authors 以搜索以特定字符串值开头的所有作者姓名,它将不起作用。

有什么想法吗?!

我不认为它可以在一个多对多关系实现为数组的查询中完成,因为在这种情况下 returns 包含 ID 在数组中的所有作者,并且它似乎无法对 id 表示的对象设置条件。

Join table 实现似乎更适合这个用例:创建另一个 table (BookAuthors) 包含两列:book(类型为 Pointer -> Book ) 和 author(指针类型 -> 作者)。每本有多个作者的书将由多行表示(每个作者一行),但您可以为 Book 或 Author

中的任何字段指定任何条件
ParseQuery.getQuery("BookAuthor")
    .include("book")
    .include("author")
    .whereStartsWith("author.name", "xxxx")
    .findInBackground(...)

最后您只需要过滤结果以仅包含不同的书籍。