2
我正在尋找一種方式來建立User
S之間的關係,在那裏你可以在Neo4j.rb同時使用in
,out
和both
所有。使用的has_many「都」在neo4j.rb
這是我到目前爲止有:
class User
include Neo4j::ActiveNode
has_many :both, :friends, type: :connection, model_class: User
has_many :out, :following, type: :connection, model_class: User
has_many :in, :followers, type: :connection, model_class: User
end
以下工作:
me = User.create
you = User.create
me.followers << you
me.followers.to_a
#=> [you]
you.following.to_a
#=> [me]
的上述相反的工作也是如此。但是,這似乎並沒有工作:
me.friends << you
you.following.to_a
#=> []
或者:
me.followers.to_a
#=> []
然而,這並不:
me.following.to_a
#=> [you]
啊,這很有道理。深入挖掘它,這是一個功能,我不認爲我需要這種方式。 – bswinnerton
太棒了;)另外我忘了提及:你應該養成像'model_class'這樣的字符串使用習慣,''model_class:'User'' –
會做!萬分感謝。 – bswinnerton