Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Created March 19, 2019 19:32
Show Gist options
  • Save mustmodify/a64d6994bbbcad6ca902d9b796652f65 to your computer and use it in GitHub Desktop.
Save mustmodify/a64d6994bbbcad6ca902d9b796652f65 to your computer and use it in GitHub Desktop.
The initial way would be:
If you had a table clubs_people
int club_id
int person_id
class Club < ActiveRecord::Base
has_and_belongs_to_many :people
end
class People < ActiveRecord::Base
has_and_belongs_to_many :clubs
# Rails would assume a table named clubs_people unless you specified otherwise
end
# A more sophisticated way would be to create a memberships table, which might have meta-attributes like date joined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment