3 ms·
About point (6), how is this handled in Rails? I mean, in Activeadmin etc or did you mean something else?
by joelbluminator 8y ago
About point (6), how is this handled in Rails? I mean, in Activeadmin etc or did you mean something else?
- busterarm 8y agoYou take advantage of what the database gives you already (via Active Record) and Friendship is its own model of which People are members. People have many Friends (People) through Friendships. Friendships have many People. You stick a check in the update controller for Friendship to destroy the object unless it has two members (or not to create without two) and additionally you add a "validates_numericality_of :friends, on: [:create, :destroy]" check on the model itself. When someone "friends" another user, you create a new Friendship with both users as members. It's automatically bidirectional (but you probably want to add some approval logic in here, which is still pretty easy). The manage friends page discussed is just a collection of all of the Friendships of which you are a member. You can use either update or destroy to remove you from membership, because now either will achieve the same thing.
- joelbluminator 8y agoOK, I wasn't aware of a many to many pain in Django. Good to know.