Skip to content

Instantly share code, notes, and snippets.

@Chryus
Last active August 29, 2015 13:56
Show Gist options
  • Save Chryus/8899960 to your computer and use it in GitHub Desktop.
Save Chryus/8899960 to your computer and use it in GitHub Desktop.
Data modeling in rails: example of has_many :through model associations
class Carrot < ActiveRecord::Base
has_many :communities
has_many :rabbits, :through => :communities
end
class Bunny < ActiveRecord::Base
has_many :communities
has_many :carrots, :through => :communities
end
class Community < ActiveRecord::Base
belongs_to :carrot
belongs_to :bunny
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment