Rails: How do self-referential has_many models work?

…衆ロ難τιáo~ 提交于 2019-11-28 20:42:01
Wizard of Ogz

Checkout coreyward's answer to the question here: Creating a model that has a tree structure

Basically you want to add a "parent_id" field to your folders table and then set up a relationship in your Folder model like this:

belongs_to :parent, :class_name => "Folder"
has_many :folders, :foreign_key => "parent_id"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!