2258

Neo4j gem - Detailed Querying direction with has_many: both

I was able to do a specific pattern match from this original question Neo4j gem - Preferred method to deal with admin relationship via this

Event.query_as(:event).match("(event)<-[invite:invited]-(user1:User)<-[friends_with:friends_with]-(user2:User)").where('invite.admin = true').pluck(:event)

I was unable to get a modified version such as this to work

current_user.friends.events.query_as(:event).match("(event)<-[invite:invited]-(user:User)").where(invite: {admin: true}).pluck(:event)

So what I actually changed was I changed the direction for the from_node and to_node in my invite class

from_class User to_class Event type 'invited'

It was previously set as from Event to User. One of my questions is, why did I have to change that to make the query work? Doesn't the has_many: both mean that direction doesn't matter?

Another change was changing my relationship type to lower case. In my model it is written in all lowercase which does seem to matter. I thought both would be converted to all uppercase like the way neo4j does it but as it stands right now, it doesn't.

I do think I need to get the current_user method working as I only want the events of the current_user's friends. Suggestions?

Answer1:

Okay, I was mixing up two different style of queries

For example in the docs they have this when you have already chained up to the lesson

s.lessons(:l, :r).where("r.start_date < {the_date} and r.end_date >= {the_date}").params(the_date: '2014-11-22').pluck(:l)

And something like this

Student.query_as(:s).where("s.age < {age} AND s.name = {name} AND s.home_town = {home_town}").params(age: params[:age], name: params[:name], home_town: params[:home_town]).pluck(:s)

Pay attention to where you place things like . and the query_as versus the lessons(:l, :r) part

My final query that worked eliminated any match components because I was already at the relationship and node that I was querying. So it looks something like this.

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)

Would still like an answer to some of my questions above though!

Recommend

  • Laravel sync not working with empty array
  • Ruby, create array without key values from existing one
  • Laravel Eloquent with two “WHERE NOT IN” in subquery
  • printk - showing in message log but not in terminal for any kernel log level
  • Functions returning a const value [duplicate]
  • How do I get a positive modulo on a negative dividend
  • Pattern combining type test and literal
  • How do I narrow down scope when running an ansible playbook?
  • HTML file fetched using 'wget' reported as binary by 'less'
  • Is there a way to query who are activesync/bb users through Exchange PowerShell?
  • Will WaitForMultipleObjects modify the state of *multiple* objects? [duplicate]
  • Changing Entity's State in Entity Framework 4.1
  • EF6 and pre-generated views
  • javascript Confirm replacement with return true/false
  • windows batch file combine csv in a folder by column
  • Add Jpanel to Jframe NetBeans
  • cannot load gems in test environment
  • Put percent labels next to legend instead of in the slice
  • HABTM associations in Rails : collecting and counting the categories of a model's children
  • DNS Lookup failed - Error with all browsers [closed]
  • php show all images in directory and sort by last modified
  • Comparing user's facebook/twitter friends to site's users in Python/Django
  • EF 4.1 DBContext AutoDetectChangesEnabled
  • Guava how to copy all files from one directory to another
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • Unable to decode certificate at client new X509Certificate2()
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Row Count Is Returning the incorrect number using RaptureXML
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Spring Data JPA custom method causing PropertyReferenceException
  • Launch Runnable Jar from Web Start
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Excel - Autoshape get it's name from cell (value)
  • WinForms: two way TextBox problem
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF