Clam
Clam

Reputation: 945

Neo4j gem - Querying from an array object

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?

Upvotes: 1

Views: 277

Answers (1)

subvertallchris
subvertallchris

Reputation: 5482

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.

Upvotes: 1

Related Questions