Created
July 25, 2022 13:11
-
-
Save djberg96/8c2d4571b78348ec42291e59c3a1defd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user.rb | |
class User < ApplicationRecord | |
has_many :groups_users, :class_name => 'GroupsUsers' | |
has_many :groups, :through => :groups_users | |
end | |
# group.rb | |
class Group < ApplicationRecord | |
has_many :groups_users, :class_name => 'GroupsUsers' | |
#has_many :users, :through => :groups_users | |
def users | |
User.all # requires eager loading | |
end | |
end | |
# groups_users.rb | |
class GroupsUsers < ApplicationRecord | |
belongs_to :group | |
belongs_to :user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment