How to remove relationships in Neo4jRB 3.0?

I have two models:

class Topic include Neo4j::ActiveNode has_many :in, :favorited_by, model_class: User, origin: :favorite_topics end 

and

 class User include Neo4j::ActiveNode has_many :out, :favorite_topics, model_class: Topic, type: 'favorited_by' end 

How can I remove only a union?

 irb(main):008:0> Topic.first.favorited_by.delete(User.first) NoMethodError: undefined method `delete' for #<Neo4j::ActiveNode::Query::QueryProxy:0x00000004b27f10> 

Thanks.

+6
source share
2 answers

Sorry for my first answer, I thought it was a has_many association. This works, but it is not ideal:

 topic = Topic.first user = User.first topic.favorited_by = topic.favorited_by.to_a - [user] 

EDIT:

 topic.favorited_by(:user, :rel).match_to(user).delete_all(:rel) 

It's a little better, but still not great. I just created a github problem for this:

https://github.com/neo4jrb/neo4j/issues/630

+7
source

Piggybacking on Brian's comment, you can do Topic.first.favorited_by.first_rel_to(User.delete).destroy if you are using the latest version 4.0.0.rc.1 and know that you only have one relationship between them.

If you are using the main branch from Github, I just added the delete and destroy methods to QueryProxy. Topic.first.favorited_by.delete(User.first) will be launched from the database, Topic.first.favorited_by.destroy(User.first) will return the Ruby relation and call delete, initiating callbacks. It will be in the next release, which is due soon.

+2
source

Source: https://habr.com/ru/post/979270/


All Articles