Neo4j gem-has_many的详细查询方向:两者 [英] Neo4j gem - Detailed Querying direction with has_many: both

查看:141
本文介绍了Neo4j gem-has_many的详细查询方向:两者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从这个原始问题中进行特定的模式匹配

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)

所以我真正改变的是我在邀请类中更改了from_nodeto_node的方向

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'

先前已将其设置为EventUser.我的问题之一是,为什么必须更改它才能使查询正常工作? has_many: both并不表示方向无关紧要吗?

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?

另一个变化是将我的关系类型更改为小写.在我的模型中,它似乎全部用小写书写.我认为两者都将像neo4j那样转换为全部大写,但就目前而言,事实并非如此.

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.

我认为我需要使current_user方法正常工作,因为我只希望current_user的朋友的事件发生.有建议吗?

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?

推荐答案

好吧,我混淆了两种不同风格的查询

Okay, I was mixing up two different style of queries

例如,在文档中,当您已经链接到lesson

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)

类似这样的

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)

请注意将.query_as相对于lessons(:l, :r)部分放置在何处

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

最后一个有效的查询消除了所有match组件,因为我已经处于要查询的关系和节点上.所以看起来像这样.

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!

这篇关于Neo4j gem-has_many的详细查询方向:两者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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