1

I'm wondering if it is possible to query a property of a relationship during an association chain. The following example can help you to understand:


  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

My goal is to do something like that:

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

As far as I know, Person.socials return an AssociationProxy and with Person.socials.where(followers_count: 100) I can query the social nodes related to the Person with followers_count = 100, however I cannot query on the relationship that links Person to Social. In Cypher terms, I would like to do something like:

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

I want to specify that I'm interested in chaining via QueryProxy and AssociationProxy, I don't need a Cypher query string ('MATCH (n:Person) ..'). The following could be a good approach

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

but my query should be as much dynamic as possible, so I would like to avoid both:

  • explicit variable naming like :s and :rel in the example
  • string query in the where clause
Sbunzini
  • 542
  • 2
  • 8

0 Answers0