Created
October 5, 2010 15:32
-
-
Save franciscoj/611736 to your computer and use it in GitHub Desktop.
many-to-many on RoR
This file contains 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 Article | |
has_many :categories, :through => :category_articles | |
has_many :category_articles | |
end |
This file contains 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 Category | |
has_many :articles, :through => :category_articles | |
has_many :category_articles | |
end |
This file contains 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 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