-
-
Save leejarvis/1049216 to your computer and use it in GitHub Desktop.
Example of has_many :through
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
class UserProject < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :project | |
belongs_to :creator, :class_name => "User" | |
# add whatever else you want here, this is your join model | |
end | |
class User < ActiveRecord::Base | |
has_many :user_projects | |
has_many :projects, :through => :user_projects | |
end | |
class Project < ActiveRecord::Base | |
has_many :user_projects | |
has_many :users, :through => :user_projects | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment