5
I’m developing a system in ruby on Rails, and I’m stuck on a question. 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. 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 couldn’t define the father or add the children. Could you give me a hint of what to do?
You can show the table structure "in"?
– Luiz Carvalho
If it can include the structures and models for the class
arvore
also helps.– Bruno Coimbra
I believe you can easily do using the Gem Ancestry
– Arthur Felipe