I'm developing a system in ruby on rails, and I'm stuck on one issue. My question is this: I need to create a tree, and then create my 'no' object and I would like it to have a 'no' parent and a 'no' child list. I tried the following approach:
class No< ApplicationRecord
belongs_to :arvore # Objeto pai
belongs_to :pai, class_name: "No", primary_key: "pai_id" #Atributo do pai
has_many :filhos, class_name: "No" ,foreign_key: "filho_id" # Lista de filhos
end
But I could not define the parent or add the children. Could you guys give me a hint of what to do?