我的代码中有一个查询,它在一个对象中搜索多个 id。在表PreparationPhytoterapic
中包含以下字段:(phytoterapicItem_id
外键),preparationItem_id
(外键)和id
。问题是当 apreparationItem_id
包含多个条目时,它会再次添加到列表中。
我尝试使用if(!listPreparations.contains(preparationContents2.get(0)))
但不起作用。
任何的想法?
preparationphytoterapicDao = getHelper().getPreparationPhytoterapicDao();
QueryBuilder<PreparationPhytoterapic, Integer> queryBuilder2 =
preparationphytoterapicDao.queryBuilder();
Where<PreparationPhytoterapic, Integer> where2 = queryBuilder2.where();
SelectArg selectArg = new SelectArg();
where2.eq("phytoterapicItem_id", selectArg);
PreparedQuery<PreparationPhytoterapic> preparedQuery2 = queryBuilder2.prepare();
List<PreparationPhytoterapic> preparationphytoterapics;
QueryBuilder<PreparationContent, Integer> queryBuilder3 =
preparationContentDao.queryBuilder();
Where<PreparationContent, Integer> where3 = queryBuilder3.where();
SelectArg selectArg2 = new SelectArg();
where3.eq("id", selectArg2);
PreparedQuery<PreparationContent> preparedQuery3 = queryBuilder3.prepare();
List<PreparationContent> preparationContents2;
for(int j = 0; j < listPhytoterapics.size(); j++) {
selectArg.setValue(listPhytoterapics.get(j).getPhytoterapicItem().getId());
preparationphytoterapics = preparationphytoterapicDao.query(preparedQuery2);
if(preparationphytoterapics.size() != 0) {
for(int k = 0; k < preparationphytoterapics.size(); k++) {
selectArg2.setValue(preparationphytoterapics.get(k).getPreparationItem().getId());
preparationContents2 = preparationContentDao.query(preparedQuery3);
if(!listPreparations.contains(preparationContents2.get(0)))
listPreparations.add(preparationContents2.get(0));
}
}