【问题标题】:Same relation is created two times between two nodes in neo4j in ruby在 ruby​​ 中的 neo4j 中的两个节点之间创建了两次相同的关系
【发布时间】:2016-02-28 12:06:31
【问题描述】:

我有两种类型的节点“发布”和“评论”,我正在使用 ruby​​ 的 ActiveNode 来创建节点和关系。以下是我的帖子和评论模型:

class Comment 
  include Neo4j::ActiveNode
  property :body, type: String

  has_one :out, :post, type: :comments_on
end

class Post 
  include Neo4j::ActiveNode
  property :title, type: String
  property :body, type: String

  has_many :in, :comments, origin: :post 
end

当我在特定帖子上创建评论时,会创建关系,但会创建两次。我无法找到为什么它被创建了两次。

这里分享代码创建评论类

def create
     @comment = Comment.new(comment_params)

        respond_to do |format|
          if @comment.save
            format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
            format.json { render :show, status: :created, location: @comment }
          else
            format.html { render :new }
            format.json { render json: @comment.errors, status: :unprocessable_entity }
          end
        end
      end

【问题讨论】:

  • 你能分享你用来创建评论的代码吗?另外,如果对您更好,欢迎您加入我们的聊天室:gitter.im/neo4jrb/neo4j
  • 我分享了创建评论的代码,请帮助我。
  • 你能输出comment_params.inspect并分享吗?
  • 你能解释一下吗?我没听懂。
  • 代码并没有告诉我太多。传递给Comment.newcomment_params 变量可能具有相关的详细信息。您能否在create 方法的开头添加puts comment_params.inspect,然后将输出复制/粘贴到您的问题中?

标签: ruby-on-rails ruby neo4j


【解决方案1】:

其他人问了这个问题,我只是能够将其追溯到 gem 6.0.2 版本中出现的错误。我想我现在已经修复了这个错误。在您的 Gemfile 中尝试以下操作:

gem 'neo4j', github: 'neo4jrb/neo4j', branch: '6.1.x'

如果这对你有用,我可以发布一个带有修复的 gem

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多