开发者

Bidirectional relationships in ActiveRecord [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜