复杂谓词与多对一关系不能正常工作 [英] Complex predicate with to-many relationship not working correctly

查看:244
本文介绍了复杂谓词与多对一关系不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我可以搜索房间预订。



在我的第一个视图中,我可以选择一个城市和街道。
在第二个视图中,我可以选择一些属性(如wlan,tv ...)



在第三个视图中, 。



当我不选择属性时,它应该显示所有可用于所选街道/城市的房间。



这是我的谓词到目前为止:

  NSPredicate * predicate = 
[NSPredicate predicateWithFormat:
@((raumattribute.schalter CONTAINS YES)AND\
(strasse.checks CONTAINS YES或strasse.standort.ortcheck CONTAINS YES))\
OR\
(raumattribute.schalter CONTAINS NO)AND\
(strasse.checks CONTAINS YES或strasse.standort.ortcheck CONTAINS YES))];

问题是,我不能过滤房间的属性。当我选择城市,去房间,我可以看到在城市的所有房间。
但是,一旦我选择了一个属性,它不会过滤房间,但会显示所选城市的所有房间。



当我写我的谓词像这样:

  NSPredicate * predicate = 

[NSPredicate predicateWithFormat:
@ (raumattribute.schalter CONTAINS YES)AND\
(strasse.checks CONTAINS YES或strasse.standort.ortcheck CONTAINS YES))

我可以过滤房间的街道和属性。但是,当没有选择的属性,我不能看到任何房间在选定的街道。



这是我更新的模式的屏幕截图:截图

解决方案

您错误地将核心数据框架(一个对象图)与SQL数据库替换,这可以辩论 ad nauseam

正确的方法是过滤房间然后通过结果迭代,排除没有选中属性的那些。结果数组可以是结果表的数据源



但是,从 / strong>和我观察的德国实体和属性名称,似乎你应该考虑修改你的数据结构。如果您编辑您的问题,并发布您的数据模型方案,我可以给你进一步的意见。


I have an app where i can search for a room to book it.

In my first view I can select a city and the street. In the second view I can select some attributes (like wlan, tv...)

In the 3rd view are the rooms that are available to the selection.

When I don't select an attribute, it should show me all the rooms that are available for the selected street/city.

Here is my predicate so far:

   NSPredicate *predicate =
[NSPredicate predicateWithFormat:
 @"((raumattribute.schalter CONTAINS YES) AND\
 (strasse.checks CONTAINS YES OR strasse.standort.ortcheck CONTAINS YES)) \
 OR\
 ((raumattribute.schalter CONTAINS NO) AND\
 (strasse.checks CONTAINS YES OR strasse.standort.ortcheck CONTAINS YES))"];

The problem is, i can't filter the rooms anymore with the attributes. When I select the city and go to the rooms, I can see all the rooms in the city. But as soon as I select an attribute it doesn't filter the rooms, but shows all the rooms in the selected city.

When I write my predicate like this:

 NSPredicate *predicate =

[NSPredicate predicateWithFormat:
 @"((raumattribute.schalter CONTAINS YES) AND\
 (strasse.checks CONTAINS YES OR strasse.standort.ortcheck CONTAINS YES)) 

I can filter the rooms with the streets and the attributes. .But when no attribute is selected, I can't see any room in the selected street.

here is a Screenshot of my updated schema: Screenshot

解决方案

You are mistaking the core-data framework, which is an object graph, with an SQL database substitute. This can be debated ad nauseam so let's not get into a philosophical discussion.

The proper way to do this from your problem description is to filter the rooms by street and then iterate through the result to exclude those that do not have the checked attributes. The resulting array could be the datasource of your resulting table.

However, from your code examples and the German entity and attribute names I am observing, it seems that you should perhaps consider revising your data structure. If you edit your question and also post your data model scheme I can give you further comments.

这篇关于复杂谓词与多对一关系不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆