This goes back to my issue with this Neo4J Gem - Saving undeclared relationships
In the documentation, they give an example of this
post.comments = [comment1, comment2] # Removes all existing relationships
post.comments << comment3 # Creates new relationship
From what I understand, the first line would remove all relationships because it's manually setting all the associated comments to be comment1, comment2.
But what does line 2 do? post.comments
should be retrieving the comments associated with post. Thus it seems to be creating a relationship with comment3 and the other comments. But don't we want to create a relationship between Posts and comments?
Either I'm not understanding the syntax and what it's doing or what is written isn't clear what is happening.
Looking at my example, we have
def create
@event_question = EventQuestion.new(event_question_params)
if @event_question.save
event = Event.find(params[:event_id])
@event_question.update(admin: current_user.facebook_id)
@event_question.events << event
redirect_to @event
else
redirect_to :back
end
end
If event
is my event node and @event_question
is my event_question node, why does @event_question.events << event
create the relationship between my event_question and event?
Right now I'm getting an undefined method '<<' for nil:NilClass
in my controller which is a another problem altogether.
My event.rb has
has_many :in, :event_questions, type: 'questions_of'
and my event_question.rb has
has_one :out, :events, origin: :event_questions
@event_question
and event
both exist but @event_question.events
will return nil