Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的Event模型需要有一个自引用连接。每个事件都可以属于另一个事件。所以有一个父母。一个事件不能属于任何其他父母。
Event
我阅读了有关该主题的 AR 文档,但由于某种原因,我一直对我应该在模型中使用什么关系感到困惑。
关于使用什么关系的任何建议?
怎么样?
belongs_to :parent, :class_name => 'Event', :foreign_key => :parent_id has_many :children, :class_name => 'Event'
注意:您必须将该列添加parent_id到事件表中
parent_id