Драгоценный камень Neo4j - зависимый: :destroy не уничтожает

Проблема: зависимое уничтожение не происходит с этой установкой! Помогите определить проблему!

У события есть вопросы, и на каждый вопрос может быть много ответов

событие.rb

  include Neo4j::ActiveNode

  has_many :both, :users, model_class: 'User', rel_class: 'Invite'
  has_many :in, :event_questions, type: 'questions_of', dependent: :destroy

eventquestion.rb

  include Neo4j::ActiveNode

  has_one :out, :event, origin: :event_questions
  has_many :in, :event_answers, type: 'answers_of', dependent: :destroy

eventanswer.rb

  include Neo4j::ActiveNode

  has_one :out, :event_question, origin: :event_answers

event_controller.rb

   if event.destroy
        location.destroy
        flash[:success] = "Event deleted"
    else

Я на главной ветке neo4j.

драгоценный камень указывает

  neo4j (4.1.0)
  active_attr (~> 0.8)
  activemodel (~> 4)
  activesupport (~> 4)
  neo4j-core (~> 4.0.0)
  orm_adapter (~> 0.5.0)
  railties (~> 4)

Я думаю, что это не совсем уместно, но, возможно, я сумасшедший.. но у меня есть

before_action :admin_or_owner, only: [:destroy] 

на моих сайтах eventquestion.rb и eventanswer.rb

однако я не вызываю метод уничтожения контроллера в моем зависимом уничтожении, так что это не должно иметь значения?


person Clam    schedule 13.01.2015    source источник
comment
Как вы называете уничтожить? Только 1_?   -  person Brian Underwood    schedule 13.01.2015
comment
Кроме того, язык типов отношений кажется немного запутанным. Я ожидаю, что answers_of и questions_of будут в другом направлении. Или же у вас может быть что-то вроде (event)-[:has_question]->(question) и (question)<-[:answers]-(answer)   -  person Brian Underwood    schedule 13.01.2015
comment
да, это просто случай if else. просто привел первую часть в качестве примера. я всегда думал, вроде как принадлежит ассоциации, event_question принадлежит событию, event_answers принадлежит event_questions   -  person Clam    schedule 13.01.2015
comment
Возможно, это неправильно, но я часто думаю о типах отношений как о чем-то вроде предложения, которое читается по стрелке.   -  person Brian Underwood    schedule 13.01.2015
comment
Я отправил сообщение своему коллеге по драгоценному камню neo4j, который недавно проделал эту работу, чтобы узнать, может ли он взглянуть на вопрос.   -  person Brian Underwood    schedule 13.01.2015


Ответы (1)


Я думаю, что в вашем приложении происходит что-то еще, потому что, как описано, с использованием предоставленного кода все работает именно так, как я ожидаю. Я создал этот раздел вашего приложения, используя предоставленный код.

class Event
  include Neo4j::ActiveNode
    has_many :both, :users, model_class: 'User', rel_class: 'Invite'
    has_many :in, :event_questions, type: 'questions_of', dependent: :destroy
end

class User
  include Neo4j::ActiveNode
  has_many :both, :events, rel_class: 'Invite'
end

class Invite
  include Neo4j::ActiveRel
  from_class User
  to_class Event

  type 'INVITED_TO'
end

class EventQuestion
  include Neo4j::ActiveNode
  has_one :out, :event, origin: :event_questions
  has_many :in, :event_answers, type: 'answers_of', dependent: :destroy
end


class EventAnswer
  include Neo4j::ActiveNode
  has_one :out, :event_question, origin: :event_answers

end

Здесь я создаю два события, три вопроса, три ответа и связываю их вместе. Вы можете видеть, что уничтожение события уничтожает его вопросы, которые, в свою очередь, уничтожают ответы на них.

e1 = Event.create
 => #<Event> 
2.2.0 :052 > e2 = Event.create
 => #<Event> 
2.2.0 :053 > q1 = EventQuestion.create
 => #<EventQuestion> 
2.2.0 :054 > q2 = EventQuestion.create
 => #<EventQuestion> 
2.2.0 :055 > q3 = EventQuestion.create
 => #<EventQuestion> 
2.2.0 :056 > a1 = EventAnswer.create
 => #<EventAnswer> 
2.2.0 :057 > a2 = EventAnswer.create
 => #<EventAnswer> 
2.2.0 :058 > a3 = EventAnswer.create
 => #<EventAnswer> 
2.2.0 :059 > 
2.2.0 :060 >   e1.event_questions << q1
 CYPHER 4ms MATCH (start:`Event`), (end:`EventQuestion`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`questions_of`]-end | {:start_id=>23, :end_id=>25}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e0f3248 @model=EventQuestion, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05e170590 @type=:has_many, @name=:event_questions, @direction=:in, @target_class_name_from_name="EventQuestion", @target_class_option="::EventQuestion", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:questions_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventQuestion", @target_class_name_or_nil="::EventQuestion">, @context="Event#event_questions", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<Event>, :node=>nil, :rel=>nil, :caller=>#<Event>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<Event>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :061 > e1.event_questions << q2
 CYPHER 4ms MATCH (start:`Event`), (end:`EventQuestion`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`questions_of`]-end | {:start_id=>23, :end_id=>26}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e1f08f8 @model=EventQuestion, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05e170590 @type=:has_many, @name=:event_questions, @direction=:in, @target_class_name_from_name="EventQuestion", @target_class_option="::EventQuestion", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:questions_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventQuestion", @target_class_name_or_nil="::EventQuestion">, @context="Event#event_questions", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<Event>, :node=>nil, :rel=>nil, :caller=>#<Event>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<Event>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :062 > e2.event_questions << q3
 CYPHER 3ms MATCH (start:`Event`), (end:`EventQuestion`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`questions_of`]-end | {:start_id=>24, :end_id=>27}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e300108 @model=EventQuestion, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05e170590 @type=:has_many, @name=:event_questions, @direction=:in, @target_class_name_from_name="EventQuestion", @target_class_option="::EventQuestion", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:questions_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventQuestion", @target_class_name_or_nil="::EventQuestion">, @context="Event#event_questions", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<Event>, :node=>nil, :rel=>nil, :caller=>#<Event>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<Event>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :063 > q1.event_answers << a1
 CYPHER 3ms MATCH (start:`EventQuestion`), (end:`EventAnswer`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`answers_of`]-end | {:start_id=>25, :end_id=>28}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e350c20 @model=EventAnswer, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05bc4f2c0 @type=:has_many, @name=:event_answers, @direction=:in, @target_class_name_from_name="EventAnswer", @target_class_option="::EventAnswer", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:answers_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventAnswer", @target_class_name_or_nil="::EventAnswer">, @context="EventQuestion#event_answers", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<EventQuestion>, :node=>nil, :rel=>nil, :caller=>#<EventQuestion>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<EventQuestion>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :064 > q2.event_answers << a2
 CYPHER 4ms MATCH (start:`EventQuestion`), (end:`EventAnswer`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`answers_of`]-end | {:start_id=>26, :end_id=>29}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e4003a0 @model=EventAnswer, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05bc4f2c0 @type=:has_many, @name=:event_answers, @direction=:in, @target_class_name_from_name="EventAnswer", @target_class_option="::EventAnswer", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:answers_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventAnswer", @target_class_name_or_nil="::EventAnswer">, @context="EventQuestion#event_answers", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<EventQuestion>, :node=>nil, :rel=>nil, :caller=>#<EventQuestion>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<EventQuestion>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :065 > q3.event_answers << a3
 CYPHER 4ms MATCH (start:`EventQuestion`), (end:`EventAnswer`) WHERE ID(start) = {start_id} AND ID(end) = {end_id} CREATE start<-[rel0:`answers_of`]-end | {:start_id=>27, :end_id=>30}
 => #<Neo4j::ActiveNode::Query::QueryProxy:0x007fc05e4c1708 @model=EventAnswer, @association=#<Neo4j::ActiveNode::HasN::Association:0x007fc05bc4f2c0 @type=:has_many, @name=:event_answers, @direction=:in, @target_class_name_from_name="EventAnswer", @target_class_option="::EventAnswer", @callbacks={:before=>nil, :after=>nil}, @origin=nil, @relationship_class=nil, @relationship_type=:answers_of, @dependent=:destroy, @unique=nil, @target_class_name="::EventAnswer", @target_class_name_or_nil="::EventAnswer">, @context="EventQuestion#event_answers", @options={:session=>Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', :start_object=>#<EventQuestion>, :node=>nil, :rel=>nil, :caller=>#<EventQuestion>}, @node_var=nil, @rel_var=:rel0, @session=Neo4j::Server::CypherSession url: 'http://localhost:7474/db/data/' version: '2.2.0-M01', @caller=#<EventQuestion>, @chain=[], @starting_query=nil, @optional=nil, @params={}> 
2.2.0 :066 > 
2.2.0 :067 >   Event.count
 CYPHER 4ms MATCH (n:`Event`) RETURN count(n) AS count
 => 2 
2.2.0 :068 > EventQuestion.count
 CYPHER 3ms MATCH (n:`EventQuestion`) RETURN count(n) AS count
 => 3 
2.2.0 :069 > EventAnswer.count
 CYPHER 3ms MATCH (n:`EventAnswer`) RETURN count(n) AS count
 => 3 
2.2.0 :070 > 
2.2.0 :071 >   e1.destroy
 Event#event_questions 31ms MATCH (event23:`Event`), (result_event_questions:`EventQuestion`), event23<-[rel0:`questions_of`]-(result_event_questions:`EventQuestion`) WHERE ID(event23) = {ID_event23} RETURN result_event_questions | {:ID_event23=>23}
 EventQuestion#event_answers 29ms MATCH (eventquestion26:`EventQuestion`), (result_event_answers:`EventAnswer`), eventquestion26<-[rel0:`answers_of`]-(result_event_answers:`EventAnswer`) WHERE ID(eventquestion26) = {ID_eventquestion26} RETURN result_event_answers | {:ID_eventquestion26=>26}
 EventQuestion#event_answers 31ms MATCH (eventquestion25:`EventQuestion`), (result_event_answers:`EventAnswer`), eventquestion25<-[rel0:`answers_of`]-(result_event_answers:`EventAnswer`) WHERE ID(eventquestion25) = {ID_eventquestion25} RETURN result_event_answers | {:ID_eventquestion25=>25}
 => true 
2.2.0 :072 > EventQuestion.count
 CYPHER 4ms MATCH (n:`EventQuestion`) RETURN count(n) AS count
 => 1 
2.2.0 :073 > EventAnswer.count
 CYPHER 3ms MATCH (n:`EventAnswer`) RETURN count(n) AS count
 => 1 
2.2.0 :074 > 
2.2.0 :075 >   e2.destroy
 Event#event_questions 31ms MATCH (event24:`Event`), (result_event_questions:`EventQuestion`), event24<-[rel0:`questions_of`]-(result_event_questions:`EventQuestion`) WHERE ID(event24) = {ID_event24} RETURN result_event_questions | {:ID_event24=>24}
 EventQuestion#event_answers 29ms MATCH (eventquestion27:`EventQuestion`), (result_event_answers:`EventAnswer`), eventquestion27<-[rel0:`answers_of`]-(result_event_answers:`EventAnswer`) WHERE ID(eventquestion27) = {ID_eventquestion27} RETURN result_event_answers | {:ID_eventquestion27=>27}
 => true 
2.2.0 :076 > EventQuestion.count
 CYPHER 3ms MATCH (n:`EventQuestion`) RETURN count(n) AS count
 => 0 
2.2.0 :077 > EventAnswer.count
 CYPHER 3ms MATCH (n:`EventAnswer`) RETURN count(n) AS count
 => 0 
2.2.0 :078 > 
person subvertallchris    schedule 13.01.2015
comment
я больше изолировал проблему вокруг моей настройки с event по event_question. все еще не уверен, где искать, так как оставшийся код уничтожения делает такие вещи, как изменение количества событий пользователей. user.events_attended -= 1 и т.д.. user.save - person Clam; 13.01.2015
comment
поэтому по какой-то причине изменение количества этих свойств мешает ему. что я сделал, так это переместил его после действий по уничтожению. Если бы он у меня был раньше, он разорвал бы цепочку уничтожения. - person Clam; 17.01.2015