NSPredicate遍历关系(StackMob) [英] NSPredicate traversing relationship (StackMob)

查看:121
本文介绍了NSPredicate遍历关系(StackMob)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索Apple的谓词编程指南和SO,试图确定为某个获取请求编写谓词的正确方法。

I have been scouring Apple's Predicate Programming Guide and SO as well, trying to determine the correct way to write a predicate for a certain fetch request.

看起来像我尝试使用点符号来遍历关系的方式没有得到请求的尊重。

It seems like the way I am attempting to use dot notation to traverse a relationship is not being respected by the request.

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:context];

[fetchRequest setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"project.user == %@", self.user];

[fetchRequest setPredicate:predicate];






用户,项目和任务都是核心数据映射到BaaS提供商的实体(StackMob)。


User, Project, and Task are all core data entities mapping to a BaaS provider (StackMob).

关系如下:用户 一对多 项目 一对多 任务与您期望的反向关系。我要做的是获取当前登录用户的所有任务。所以,我的想法是:发送一个带有实体任务的获取请求。拥有该任务的项目由登录用户拥有,获取该任务并显示它。很简单。

Relationships are as follows: User one-to-many Project one-to-many Task with inverse relationships as you would expect. What I am trying to do is get all tasks for the current logged in user. So, my thinking is: send a fetch request with the entity "Task". Where the project that owns the task is owned by the logged in user, get that task and display it. Simple enough.

我认为我应该能够在我上面显示的谓词中使用点表示法,但是获取请求返回nil 。

And I think I should be able to use the dot notation in the predicate that I have shown above, but the fetch request is returning nil.

关于获取请求的其他所有内容都没问题。如果我将格式字符串更改为 @project!= NULL,我将恢复所有任务。

Everything else about the fetch request is fine. If I change the format string to @"project != NULL", I get all of the tasks back.

我只是错误地编写了格式字符串吗?向StackMob发送获取请求时,点符号在某种程度上无效吗?

Am I just writing my format string incorrectly? Is dot notation somehow not valid when sending a fetch request to StackMob?

一如既往,非常感谢任何帮助。

As always, any help is greatly appreciated.

如果需要更多信息,请与我们联系。我现在有点太近了,不能清楚地看到它。

Please let me know if more information is needed. I'm a little too close to this right now to see it clearly.

推荐答案

StackMob不支持关系的属性(project.user == X的任务)。但是,您似乎正在尝试为登录用户获取给定项目的所有任务。如果我认为登录用户是创建项目和任务的用户是正确的,那么将项目架构的权限设置为允许sm_owner。然后,您可以根据项目ID(项目IN 1234中的任务)或基于ID的项目获取任务,并获取所有任务(项目中projectId == 1234并使用任务值关系)。无论哪种方式,使用该权限提取仅返回sm_owner ==登录用户的结果,因此您不需要设置提取,以便它使用用户ID作为过滤器。希望有所帮助!

Fetching on an attribute of a relationship (task where project.user == X) is not supported by StackMob. However, it looks like you are trying to get all the tasks for a given project for the logged in user. If I am correct in assuming that the logged in user was the one to create the projects and tasks, then set the permissions of the project schema to "Allow to sm_owner". You can then fetch tasks based on the project ID (task where project IN 1234), or project based on ID and grab all tasks (project where projectId == 1234 and use value of tasks relationship). Either way, with that permission fetches will only return results where sm_owner == logged in user, so you don't need to set up the fetch such that it uses the user ID as a filter. Hope that helps!

这篇关于NSPredicate遍历关系(StackMob)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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