gpt4 book ai didi

android - Parse.com 上的一对多关系

转载 作者:搜寻专家 更新时间:2023-11-01 08:53:23 25 4
gpt4 key购买 nike

我在 Parse.com 上有两个类:图像和用户。在用户类中,我保存了 3 个字段名称、手机号码和职业。在图像类中,我正在保存图像。

我必须在这两个类之间创建一对多关系,以便我可以使用相应的手机号码获取图像。

我在 parse.com 上创建了 User 类和 Image 类之间的关系,在 User 类中有一个名为 Mobile 的列。无法找到如何以一对多关系获取具有该特定手机号码的图像。请帮忙,因为我已经阅读了文档。提前致谢。

最佳答案

这只是要执行的代码。你将不得不考虑周到地组织你的类(class)。我不确定您打算如何进行,但就编码而言,以下内容应该有所帮助。

首先获取当前用户。

ParseUser currentUser = ParseUser.getCurrentUser();

因为您在 User 表中有“mobile”列作为关系,所以首先获取关系。像这样。

ParseRelation<ParseObject> relation = currentUser
.getRelation("mobile");

一旦获得关系,就可以查询需要的对象。在您的例子中,它是图像对象。

ParseQuery<ParseObject> query = relation.getQuery("Image");

在这里,您可以自定义您的查询。例如:

query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject, ParseException e) {
if(e == null)
//your code
//List<ParseFile> pFileList = (ArrayList<ParseFile>) object.get("images"); //something like this just to give an idea
}

});

或者如果你有多个对象,使用

query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
for (ParseObject object : list) {

ParseFile image = (ParseFile) object.get("images_column_name");

}
}
}
});

关于android - Parse.com 上的一对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com