通过实体中的列表对象化查询过滤器包含搜索参数 [英] objectify query filter by list in entity contains search parameter

查看:75
本文介绍了通过实体中的列表对象化查询过滤器包含搜索参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序中,我有一个包含其他实体列表的实体(假设一个事件持有分配的员工列表)

使用objectify的

- 我需要找到分配给特定员工的所有事件。

是否有一种基本的方式来过滤含有参数的查询 - 类型与查询中的相反



...快速伪代码

  findAll(Employee employee){
...
return ofy.query(Event.class).filter(employees.contains,employee).list();
}

任何帮助将不胜感激






我在看过这个 http://groups.google.com/group/objectify-appengine/browse_thread/thread/77ba676192c08e20 - 但不幸的是这会给我一个空的列表



目前我正在做一些非常低效的事情 - 通过每个事件,遍历员工并将其添加到新列表中,如果它包含给定的员工只是为了让一些工作 - 我知道这是虽然






让我补充一件事,

上面的查询实际上并不是什么,我只是用它,因为我不认为这会有所作为。



Employee和Events在同一个实体中作为父母的商业团体



实际我使用的查询如下所示:

  ofy.query(Event.class).ancestor(businessKey).filter(employees ,employee).list(); 

不幸的是,这仍然返回一个空列表 - 是否有祖先(键)过滤器?






解决方案,员工字段没有正确编制索引。



我添加了datastore-indexes文件来创建一个复合索引,但是最初是根据我在雇员字段索引之前添加的一个值进行测试的,这是我做的一些愚蠢的事 - 只需在业务领域和员工领域固定一切。数据存储索引文件似乎没有必要,删除它后,再次尝试一切正常。

解决方案

一般来说,你以下两种方法之一:

 将Set< Key< Employee>>事件



 放置Set< Key< Event>>的属性在员工

你也可以创建一个关系实体,但如果你只是对值进行过滤计数相对较低,通常只需将set属性放在一个实体或另一个实体上就可以了。

然后按照您的描述过滤:

  ofy.query(Event.class).filter(employees,employee).list()

或者

  ofy.query(Employee.class)。 filter(events,event).list()

list属性应该包含Keys目标实体。如果你将一个实体传递给filter()方法,Objectify会理解你想用键来过滤。


in an app i have an entity that contains a list of other entities (let's say an event holding a list of assigned employees)

using objectify - i need to find all the events a particular employee is assigned to.

is there a basic way to filter a query if it contains the parameter - kind of the opposite of the query in

... quick pseudocode

findAll(Employee employee) {
  ...
  return ofy.query(Event.class).filter("employees.contains", employee).list();
}

any help would be greatly appreciated


i tried just doing filter("employees", employee) after seeing this http://groups.google.com/group/objectify-appengine/browse_thread/thread/77ba676192c08e20 - but unfortunately this returns me an empty list

currently i'm doing something really inefficient - going through each event, iterating through the employees and adding them to a new list if it contains the given employee just to have something that works - i know this is not right though


let me add one thing,

the above query is not actually what it is, i was just using that because i did not think this would make a difference.

The Employee and Events are in the same entity group with Business as a parent

the actual query i am using is the following

ofy.query(Event.class).ancestor(businessKey).filter("employees", employee).list();

unfortunately this is still returning an empty list - does having the ancestor(key) in there mess up the filter?


solution, the employees field was not indexed correctly.

I added the datastore-indexes file to create a composite index, but was testing originally on a value that I added before the employees field was indexed, this was something stupid i was doing - simply having an index on the "business" field and the "employees" field fixed everything. the datastore-indexes file did not appear to be necessary, after deleting it and trying again everything worked fine.

解决方案

Generally, you do this one of two ways:

Put a property of Set<Key<Employee>> on the Event

or

Put a property of Set<Key<Event>> on the Employee

You could also create a relationship entity, but if you're just doing filtering on values with relatively low counts, usually it's easier to just put the set property on one entity or the other.

Then filter as you describe:

ofy.query(Event.class).filter("employees", employee).list()

or

ofy.query(Employee.class).filter("events", event).list()

The list property should hold a Keys to the target entity. If you pass in an entity to the filter() method, Objectify will understand that you want to filter by the key instead.

这篇关于通过实体中的列表对象化查询过滤器包含搜索参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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