2
レール で双方向の関係をやろうとしたとき、私はグラフは、Railsの
class Befriending < ActiveRecord::Base
belongs_to :initiator, :class_name => :User
belongs_to :recipient, :class_name => :User
after_create do |b|
BefriendingEdge.create!(:user => b.initiator, :befriending => b)
BefriendingEdge.create!(:user => b.recipient, :befriending => b)
end
end
class BefriendingEdge < ActiveRecord::Base
belongs_to :user
belongs_to :befriending
end
class User < ActiveRecord::Base
has_many :befriending_edges
has_many :friends, :through => :befriending_edges, :source => :user
has_many :befriendings, :through => :befriending_edges, :source => :befriending
end
(http://www.dweebd.com/sql/modeling-bidirectional-graph-edges-in-rails/)最近、これを見つけた。しかし、私はちょうどかなりそれがどのように動作するか理解していないが、エッジ。誰も私に説明するのを助けることができますか?それは二重のbelongs_toのように見えます。これをあまりよく理解していない。
おかげ