This is mostly a design/efficiency question but I wanted to see if there was a preferred way to handle this in neo4j as opposed to how I would do it in a sql db.
Right now I have 2 models - user
and event
. I also have a relationship between user
and event
to represent that they will attend the event. I want to figure out the best way to represent the admin of the event. In other words, I want to be able to query the events that are admined by a user.
One way to do it is to create a new relationship called admin_of
between user and event
. Another way is to create an admin property of the attending relationship. Something like admin: true
The admin_of
query seems easy but adds another relationship to the db. It would be able to handle multi admins later on as well.
The latter way could be queried by something like this I think: (From documentation) EnrolledIn.where(since: 2002)
so my search would include admin: true
. However I am not sure how to chain this as I want it to be only friends events. The other where
queries usually base the properties on the nodes rather than relationships.
The latter method seems like to be a preferred method to do it but what would be the correct way to query it? Or is the first method better for simplicity even though it adds an additional relationship?
Update: I came up with something like this
result = Event.query_as(:event).match("event<-[invite: INVITED]-(user: User)<-[:FRIENDS_WITH]-(user)").where(invite: {admin: /true/}).pluck(:event)
based off of the detailed querying in
https://github.com/neo4jrb/neo4j/wiki/Search-and-Match
Update 2
I have this right now but not getting a match. What's the best way to start disecting what's wrong with my query?
current_user.friends.events.query_as(:event).match("event<-[invite]-(user: User)<-[friends_with]-(user)").where(invite: {admin: true}, event: {detail: 'property'}).pluck(:event)
My User model has
has_many :both, :events, model_class: 'Event', rel_class: 'Invite'
and my Event model has
has_many :both, :users, model_class: 'User', rel_class: 'Invite'
and my invite model has
from_class Event
to_class User
type 'invited'