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 I can remove only association?
irb(main):008:0> Topic.first.favorited_by.delete(User.first)
NoMethodError: undefined method `delete' for #<Neo4j::ActiveNode::Query::QueryProxy:0x00000004b27f10>
Thank you.
Sorry for my first answer, I thought it was a has_many assocation. This works, but it's 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)
This is a bit better, but still not great. I just created a github issue for this:
https://github.com/neo4jrb/neo4j/issues/630
Piggybacking on Brian's comment, you can do Topic.first.favorited_by.first_rel_to(User.delete).destroy
if you're running the latest release, 4.0.0.rc.1, and know that you only have one relationship between the two.
If you're using the master branch from Github, I just added delete
and destroy
methods to QueryProxy. Topic.first.favorited_by.delete(User.first)
will run from the database, Topic.first.favorited_by.destroy(User.first)
will return the relationship to Ruby and call delete, triggering callbacks. These will be will in the next release, which should be soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With