Created
October 17, 2019 11:55
-
-
Save rebelweb/9b21117175d723e5491360b31af46a9f to your computer and use it in GitHub Desktop.
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 Category < ApplicationRecord | |
has_many :article_categories, class_name: ArticleCategory, foreign_key: :category_id, dependent: :destroy | |
has_many :articles, through: :article_categories | |
end | |
class Article < ApplicationRecord | |
belongs_to :author, class_name: User, foreign_key: :author_id | |
has_many :article_categories, class_name: ArticleCategory, foreign_key: :article_id, dependent: :destroy | |
has_many :categories, through: :article_categories | |
has_many :images, class_name: ArticleImage, foreign_key: :article_id, dependent: :destroy | |
end | |
class ArticleCategory < ApplicationRecord | |
belongs_to :article, class_name: Article, foreign_key: :article_id | |
belongs_to :category, class_name: Category, foreign_key: :category_id, counter_cache: :articles_count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment