2016-03-22 6 views
1

Neo4j/Rubyを使用して、ノードの親ノードを取得したいと考えています。明示的に関係を宣言せずに親ノードを取得する

// i can get the children node, but is there any way to access the parent nodes" 
// @decision.next.each.map{|r|...} 
// like: 
// @decision.parents... 

class Decision 
    include Neo4j::ActiveNode 

    property :title, type: String 
    property :text, type: String 
    property :ending, type: Boolean, default: nil 
    property :rooting, type: Boolean, default: nil 

    has_many :out, :next, rel_class: :Action, model_class: :Decision 

    validates_uniqueness_of :input 

end 

class Action 
    include Neo4j::ActiveRel 
    before_save :check_input_type 

    from_class :Decision 
    to_class :Decision 
    type 'action' 

    property :input, type: Integer 
    property :expected_input, type: Integer 

    validates_presence_of :input 
    creates_unique :none 

end 

答えて

0

これはかなり簡単です。あなただけの各Decision

のための1つの親があると予想される場合

class Decision 
    include Neo4j::ActiveNode 

    # ... properties 

    has_many :out, :next, rel_class: :Action, model_class: :Decision 

    # The straightforward way 
    has_many :in, :parents, rel_class: :Action, model_class: Decision 

    # Using `origin` 
    has_many :in, :parents, origin: :next, model_class: :Decision 
end 

協会はまた、簡単has_oneにすることができます。あなたはいくつかの方法でそれを行うことができます

関連する問題