我有一个名为Tags的模型,其中每个标记都有一个名称和描述,但标记可以是其他标记的父标记。
我想在我的模型中添加一个parent_id,但我想知道是否可以将Rails Admin配置为将子项与父项相关联(来自同一模型的另一条记录)。
谢谢:)
答案 0 :(得分:0)
找到它:Creating a model that has a tree structure
感谢coreyward :)
class Tag < ActiveRecord::Base
attr_accessible :description, :name, :parent_id
has_many :children, class_name: "Tag", foreign_key: "parent_id"
belongs_to :parent, class_name: "Tag",primary_key: "id"
end