I am working on a neo4j rails project that involves a parent-child type relationship between nodes from the same model. Any child can have multiple parents. I would like to be able to create the parent-child relationships when I create a new child. How should I implement this? Currently, the app is set up to only create one parent-child relationship when the child is created.
# View for ...things/new
<div class="new-thing-form">
<%= form_for(@thing) do |f| %>
<%= f.text_field :name, placeholder: "Thing Name" %>
<%= text_field_tag :parent, '', placeholder: "Parent Name" %>
<%= f.submit "Create Thing" %>
<% end %>
</div>
# Model for Thing
class Thing
include Neo4j::ActiveNode
property :name, type: String
property :description, type: String
has_many :out, :children_things, type: :PARENT_OF, model_class: :Thing
has_many :in, :parent_things, model_class: :Thing, origin: :children_things
validates_presence_of :name
end
I've considered three possible solutions so far and am having trouble wrapping my head around them (I am new to web development so I apologize if this is basic stuff).
- Dynamically Add Fields
I've checked out Railscasts episode 196 and 197, however I am having trouble using "accepts_nested_attributes_for." Also, this is a relationship between nodes of the same model, so is there a way to add and remove fields without using nested attributes?
- Create a multiselect list
There are many posts on creating multiselect menus using Bootstrap and ActiveRecord. How should I implement these using Neo4j?
- Create ActiveRel for PARENT_OF relationship
Is there a way to create relationships through forms? If so, then is there a way to do that in conjunction with a nested_attributes method to create new PARENT_OF relationships when a child thing is created?
Sorry for the open-ended questions. I've been looking around for a couple of days now and would really appreciate some guidance, even if you can just point me in the right direction. Any advice would help. Thanks again.