From e1ee6f8f645c59332c61f321b383053c4d02a7d2 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 12 May 2018 14:26:43 +0900 Subject: [PATCH] [phase-6]add relation to project to term and category models --- app/models/glossary_category.rb | 1 + app/models/glossary_term.rb | 1 + db/migrate/004_add_project_to_terms_and_categories.rb | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 db/migrate/004_add_project_to_terms_and_categories.rb diff --git a/app/models/glossary_category.rb b/app/models/glossary_category.rb index b48306a..43bbade 100644 --- a/app/models/glossary_category.rb +++ b/app/models/glossary_category.rb @@ -1,3 +1,4 @@ class GlossaryCategory < ActiveRecord::Base has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id' + belongs_to :project end diff --git a/app/models/glossary_term.rb b/app/models/glossary_term.rb index 645b6f0..fd087b3 100644 --- a/app/models/glossary_term.rb +++ b/app/models/glossary_term.rb @@ -1,3 +1,4 @@ class GlossaryTerm < ActiveRecord::Base belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id' + belongs_to :project end diff --git a/db/migrate/004_add_project_to_terms_and_categories.rb b/db/migrate/004_add_project_to_terms_and_categories.rb new file mode 100644 index 0000000..295e2c5 --- /dev/null +++ b/db/migrate/004_add_project_to_terms_and_categories.rb @@ -0,0 +1,6 @@ +class AddProjectToTermsAndCategories < ActiveRecord::Migration[5.1] + def change + add_reference :glossary_terms, :project, foreign_key: true + add_reference :glossary_categories, :project, foreign_key: true + end +end