1

我想知道是否可以在关联链期间查询关系的属性。下面的例子可以帮助你理解:


  class AccountRel
    include ActiveGraph::Relationship

    from_class :Person
    to_class   :Social

    property :platform, type: [String] # Like [Instagram, Facebook]
  end


  class Person
    include ActiveGraph::Node
    self.mapped_label_name = 'Person'
    property :name, type: String
    property :gender, type: Boolean
    has_many :out, :socials, rel_class: :AccountRel, unique: true
  end


  class Social
    include ActiveGraph::Node
    self.mapped_label_name = 'Social'
    property :followers_count, type: Integer
    has_many :out, :friends, rel_class: :AccountRel, unique: true
  end

我的目标是做这样的事情:

Person.socials({query on platform property of AccountRel  relationship})
OR
Person.socials.where(node_var: {Social node properties}, rel_var: {AccountRel properties})

据我所知,Person.socials返回一个AssociationProxyPerson.socials.where(followers_count: 100)我可以查询与 Followers_count = 100 的人相关的社交节点,但是我无法查询将人链接到社交的关系。在 Cypher 方面,我想做类似的事情:

match (n:Person)-[r:AccountRel]->(s:Social)
where r.platform in ["Instagram", "Facebook"]
return n

我想指定我有兴趣通过 QueryProxy 和 AssociationProxy 进行链接,我不需要 Cypher 查询字符串('MATCH (n:Person) ..')。以下可能是一个很好的方法

Person.socials(:s, :rel).where('rel.platform IN ["Instagram", "Facebook"]')

但我的查询应该尽可能动态,所以我想避免两者:

  • 显式变量命名,如示例中的 :s 和 :rel
  • where 子句中的字符串查询
4

0 回答 0