Skip to content

Commit

Permalink
align book and case metadata classes together...
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 19, 2024
1 parent 76de302 commit bf0d9f8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
1 change: 0 additions & 1 deletion app/models/book_metadatum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# fk_rails_... (book_id => books.id)
#
class BookMetadatum < ApplicationRecord
# self.table_name = 'case_metadata'
belongs_to :book
belongs_to :user
end
3 changes: 2 additions & 1 deletion app/models/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Case < ApplicationRecord
inverse_of: :case

has_many :metadata,
dependent: :destroy
class_name: 'CaseMetadatum',
dependent: :destroy

# rubocop:disable Rails/InverseOf
has_many :queries, -> { order(arranged_at: :asc) },
Expand Down
3 changes: 1 addition & 2 deletions app/models/metadatum.rb → app/models/case_metadatum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
# case_metadata_ibfk_2 (user_id => users.id)
#

class Metadatum < ApplicationRecord
self.table_name = 'case_metadata'
class CaseMetadatum < ApplicationRecord
belongs_to :case
belongs_to :user
end
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ class User < ApplicationRecord
has_many :scores,
dependent: :destroy

has_many :metadata,
dependent: :destroy
has_many :case_metadata,
class_name: 'CaseMetadatum',
dependent: :destroy
has_many :book_metadata,
class_name: 'BookMetadatum',
dependent: :destroy

# Validations

Expand Down
Binary file modified docs/erd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 7 additions & 8 deletions test/fixtures/book_metadata.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# == Schema Information
#
# Table name: case_metadata
# Table name: book_metadata
#
# id :integer not null, primary key
# id :bigint not null, primary key
# last_viewed_at :datetime
# case_id :integer not null
# user_id :integer not null
# book_id :bigint not null
# user_id :integer
#
# Indexes
#
# case_metadata_ibfk_1 (case_id)
# case_metadata_user_id_case_id_index (user_id,case_id)
# index_book_metadata_on_book_id (book_id)
# index_book_metadata_on_user_id_and_book_id (user_id,book_id)
#
# Foreign Keys
#
# case_metadata_ibfk_1 (case_id => cases.id)
# case_metadata_ibfk_2 (user_id => users.id)
# fk_rails_... (book_id => books.id)
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand Down
File renamed without changes.

0 comments on commit bf0d9f8

Please sign in to comment.