Skip to content

Instantly share code, notes, and snippets.

@franciscoj
Created October 5, 2010 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franciscoj/611736 to your computer and use it in GitHub Desktop.
Save franciscoj/611736 to your computer and use it in GitHub Desktop.
many-to-many on RoR
class Article
has_many :categories, :through => :category_articles
has_many :category_articles
end
class Category
has_many :articles, :through => :category_articles
has_many :category_articles
end
class CategoryArticle
belongs_to :article
belongs_to :category, :counter_cache => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment