Created
March 27, 2020 18:41
-
-
Save jathayde/8d06b1c641ffd203afae0576aebd8abc to your computer and use it in GitHub Desktop.
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
module Attributable | |
extend ActiveSupport::Concern | |
included do | |
has_many :attributions, as: :attributable | |
has_many :sources, through: :attributions | |
end | |
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
# == Schema Information | |
# | |
# Table name: attributions | |
# | |
# id :bigint(8) not null, primary key | |
# attributable_type :string | |
# attributable_id :integer | |
# source_id :integer | |
# user_id :integer | |
# retrieved_on :date | |
# source_text :text | |
# description :text | |
# cross_issue :boolean | |
# cross_issue_description :text | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# | |
class Attribution < ApplicationRecord | |
belongs_to :source | |
belongs_to :attributable, polymorphic: true | |
accepts_nested_attributes_for :source, reject_if: :all_blank, allow_destroy: true | |
validates :source_id, presence: true | |
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
# == Schema Information | |
# | |
# Table name: sources | |
# | |
# id :bigint(8) not null, primary key | |
# name :string | |
# source_type :string | |
# url :text | |
# published_on :date | |
# marketable :boolean | |
# marketable_url :text | |
# marketable_details :text | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# source_text :text | |
# authors :text | |
# catalog_number :string | |
# | |
class Source < ApplicationRecord | |
has_many :attributions | |
validates :name, | |
presence: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment