Neo4j gem - Querying from an array object

青春壹個敷衍的年華 提交于 2019-12-11 08:10:56

问题


In my previous example I had this query

current_user.friends.events(:event, :rel).where("rel.admin = {admin_p} AND event.detail = {detail_p}").params(admin_p: true, detail_p: true).pluck(:event)

current_user.friends.events brings me up to events to continue my chain, but does this work for if I already have an object that contains an array of events?

In my example, I am trying to use geocoder to pull in proximity.

So I have my user and events which are geocoded.

Geocoder can do something like this

Venue.near([40.71, 100.23], 20) # find all objs within 20 miles

So I can essentially find all the events and store it in an object. Now can I use the neo4j query to filter that object?

e.g.

array_object(:event, :rel).where("rel.admin = {admin_p} AND event.detail = {detail_p}").params(admin_p: true, detail_p: true).pluck(:event)

Even if this works, is there an alternate way to do this?


回答1:


You can't call query proxy methods on an array, so just grab the IDs of those events and filter your match accordingly.

current_user.friends.events(:e).where(neo_id: array_object.map { |e| e.neo_id })

That'll filter the user's friends' events that are in that array. We can use neo_id in where for better performance.



来源:https://stackoverflow.com/questions/27178188/neo4j-gem-querying-from-an-array-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!