0

我在两个类之间有两种类型的关系。在其中一个中,我需要建立origin,但我不知道如何。有人知道吗?

class A
  include Neo4j::ActiveNode
  ...
  has_many :out, :method1, model_class: B
  has_many :out, :method2, model_class: B
  ...
end

class B
  include Neo4j::ActiveNode
  ...
  has_one :in, :something, model_class: A, origin: ?????
  ...
end

图形

关系的类型是默认类型(“#”+ 方法的名称)。

http://i.imgur.com/3MtC0k3.png

4

2 回答 2

2

如果您查看有关声明来源的文档,我认为您遇到的问题是您尚未声明设置方法的第二个参数

所以在你的课堂A上,你可能想要这样做:

has_many :out, :somethingHere :type1, model_class: B

然后在 中B,您可能想要这样做:

has_one :in, :something, model_class: A, :origin: :somethingHere

我不能告诉你应该是什么,somethingHere因为你没有提供足够的信息来说明他们的关联意味着什么。AB

于 2014-12-24T15:24:23.573 回答
0

我最终制定了自己的方法。它是这样的:

class A
  include Neo4j::ActiveNode
  ...
  has_many :out, :method1, model_class: B
  has_many :out, :method2, model_class: B
  ...
end

class B
  include Neo4j::ActiveNode
  ...
  # I removed has_one line and include:
  def something
    rel = rels(dir: :incoming).first
    return nil if rel.nil?
    rel.start_node
  end
  ...
end

这是一个很好的解决方案吗?请发表评论。

于 2014-12-24T17:41:45.763 回答