开发者

Bidirectional relationships in ActiveRecord [duplicate]

开发者 https://www.devze.com 2022-12-09 12:49 出处:网络
This question already has an answer here: How do I do reflexive self-join relationships in ActiveRecord?
This question already has an answer here: How do I do reflexive self-join relationships in ActiveRecord? (1 answer) Closed 3 years ago.

I want a "friend" relationship, as in "social site friends", which means: if I'm friending you you invariably friend me. If I remove you from friends, y开发者_如何学编程ou do that, too. (well, you get the idea).

Currently this is done with duplicate relations and an observer to add/remove the second (more correctly, "other") relation when the first gets created/deleted.

What's the convenient way to implement the subject without duplicating records in the relation table? Maybe there's a gem/plugin to do this?


Fortunately there is a Railscast on this very topic! Or if you prefer, you can read the instructions as an ASCIIcast.

0

精彩评论

暂无评论...
验证码 换一张
取 消