这又回到了我的问题与此Neo4J Gem - Saving undeclared relationshipsNeo4j的宝石协会和创建关系
在本文档中,他们给这个
post.comments = [comment1, comment2] # Removes all existing relationships
post.comments << comment3 # Creates new relationship
从我个人理解的例子,第一行会删除所有关系,因为它是手动将所有相关评论设置为comment1,comment2。
但是第2行做了什么? post.comments
应该检索与帖子相关的评论。因此它似乎正在与comment3和其他评论建立关系。但是,我们不想在帖子和评论之间建立关系吗?
要么我不理解语法,它在做什么或写什么不清楚发生了什么。在我的例子
来看,我们有
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
如果event
是我的事件节点和@event_question
是我event_question节点,为什么@event_question.events << event
创建我event_question和事件之间的关系?
现在我在控制器中得到undefined method '<<' for nil:NilClass
,这是另一个问题。
我event.rb有
has_many :in, :event_questions, type: 'questions_of'
和我event_question.rb具有
has_one :out, :events, origin: :event_questions
@event_question
和event
都存在,但@event_question.events
将返回nil
这是一个很好的问题,顺便说一句。 – subvertallchris 2014-11-21 23:20:20