Skip to content

Commit

Permalink
hook up has_many relations
Browse files Browse the repository at this point in the history
  • Loading branch information
drusepth committed Jan 17, 2019
1 parent 7ef5895 commit 5a4d92f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/author.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class Author < ApplicationRecord
has_many :books
has_many :characters, through: :books
has_many :genres, through: :books
has_many :metrics, through: :books
end
13 changes: 13 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
class Book < ApplicationRecord
has_many :book_has_genres
has_many :genres, through: :book_has_genres

has_many :publish_dates
has_many :publishers, through: :publish_dates
has_many :authors, through: :publish_dates

has_many :chapters

has_many :character_appearances
has_many :characters, through: :character_appearances

has_many :metrics, as: :prose
end
5 changes: 5 additions & 0 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class Chapter < ApplicationRecord
belongs_to :book

has_many :character_appearances
has_many :characters, through: :character_appearances

has_many :metrics, as: :prose
end
7 changes: 7 additions & 0 deletions app/models/character.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
class Character < ApplicationRecord
has_many :character_appearances
has_many :books, through: :character_appearances,
source: :prose, source_type: Book.name
has_many :chapters, through: :character_appearances,
source: :prose, source_type: Chapter.name

has_many :metrics
end
3 changes: 3 additions & 0 deletions app/models/genre.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Genre < ApplicationRecord
has_many :book_has_genres
has_many :books, through: :book_has_genres
has_many :authors, through: :book_has_genres
end
6 changes: 6 additions & 0 deletions app/models/publisher.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
class Publisher < ApplicationRecord
has_many :books
has_many :authors, through: :books
has_many :metrics, through: :books
has_many :genres, through: :books

has_many :publish_dates
end

0 comments on commit 5a4d92f

Please sign in to comment.