Back4App(Parse) に次のテーブルがあります
一致: id(文字列)、maxPlayers(Int)、スポーツ(ParseObject)
問題は、時々すべてのマッチ オブジェクトを取得しようとすると (なぜ時々実行され、他のオブジェクトが実行されないのかわかりません)、データのないスポーツ parse オブジェクトを取得することです。私が言ったように、私はオブジェクトを正しく理解します。コードは次のとおりです。
public String saveMatch(Match match) throws ParseException {
ParseObject parseObject = new ParseObject("match");
parseObject.put(COLUMN_MAX_PLAYERS, match.getMaxPlayer());
//ParseObject sport = new ParseObject("Sport");
//sport.setObjectId(match.getSport().getId());
//parseObject.put("sport", sport);
//I change to the next code but the problem continue.
ParseObject sport = ParseObject.createWithoutData(TableSport.TABLE_NAME,match.getSport().getId());
parseObject.put(COLUMN_SPORT, sport);
parseObject.save();
return parseObject.getObjectId();
}
@Override
public ArrayList<Match> getAllMatches() throws ParseException, ParseObjectException {
ParseQuery<ParseObject> query = ParseQuery.getQuery(TABLE_NAME);
List<ParseObject> objects = query.find();
return parseAllObjectsToMatchList(objects);
}
private ArrayList<Match> parseAllObjectsToMatchList(List<ParseObject> objects) throws ParseException, ParseObjectException {
ArrayList<Match> matches = new ArrayList<>();
for (int i = 0; i < objects.size(); i++){
matches.add(parseObjectToMatch(objects.get(i)));
}
return matches;
}
private Match parseObjectToMatch(ParseObject object) throws ParseException, ParseObjectException {
try{
Match match = new Match();
match.setId(object.getObjectId());
match.setMaxPlayer(object.getInt(COLUMN_MAX_PLAYERS));
ParseObject objectSport = object.getParseObject(COLUMN_SPORT);
if(objectSport!= null){
Sport sport = (sportDatabaseManager.parseObjectToSport(objectSport));
match.setSport(sport);
}
return match;
}catch (Exception e){
throw new ParseObjectException();
}
}
private Sport parseObjectToSport(ParseObject parseObject) throws ParseObjectException {
try{
ParseFile parseFile = parseObject.getParseFile(TableSport.COLUMN_IMAGE);
Sport sport = new Sport();
sport.setId(parseObject.getObjectId());
sport.setName(parseObject.getString(TableSport.COLUMN_NAME));
sport.setSumary(parseObject.getString(TableSport.COLUMN_SUMARY));
sport.setDescription(parseObject.getString(TableSport.COLUMN_DESCRIPTION));
sport.setImage(parseFile.getUrl());
return sport;
}catch (Exception e){
throw new ParseObjectException();
}
}