What would be the proper way to create a relationship between User
s that have a bidirectional relationship?
Say I have:
class User
include Neo4j::ActiveNode
property :name, type: String
property :created_at, type: DateTime
property :updated_at, type: DateTime
has_many :both, :friends, model_class: 'User', type: 'connection' unique: true
has_many :in, :followers, model_class: 'User', type: 'connection', unique: true
has_many :out, :following, model_class: 'User', type: 'connection', unique: true
end
And then,
users = [
User.create(name: 'Foo'),
User.create(name: 'Bar'),
User.create(name: 'Baz'),
]
Would this be the appropriate way to do it? It seems wildly inefficient:
users.each do |user|
user.friends << users.reject { |u| u == user }
end