Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Forked from ryanlecompte/gist:1049170
Created June 27, 2011 16:25
Show Gist options
  • Save leejarvis/1049216 to your computer and use it in GitHub Desktop.
Save leejarvis/1049216 to your computer and use it in GitHub Desktop.
Example of has_many :through
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