Class: ProjectSource
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ProjectSource
- Includes:
- Housekeeping, Shared::IsData
- Defined in:
- app/models/project_source.rb
Overview
A ProjectSource links sources to projects.
Instance Attribute Summary collapse
-
#project_id ⇒ Integer
the project.
-
#source_id ⇒ Integer
The source.
Instance Method Summary collapse
- #check_for_use ⇒ Object protected
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#project_id ⇒ Integer
the project
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/project_source.rb', line 11 class ProjectSource < ApplicationRecord include Housekeeping include Shared::IsData belongs_to :project, inverse_of: :project_sources belongs_to :source, inverse_of: :project_sources # source presence validation is handled in PG, as per accepts_nested_attributes constraints # validates_uniqueness_of :source_id, scope: [:project_id] before_destroy :check_for_use protected def check_for_use if source.citations.where(citations: {project: project_id}).any? errors.add(:base, 'Source can not be removed, it is used in this project') throw(:abort) end end end |
#source_id ⇒ Integer
Returns the source.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/project_source.rb', line 11 class ProjectSource < ApplicationRecord include Housekeeping include Shared::IsData belongs_to :project, inverse_of: :project_sources belongs_to :source, inverse_of: :project_sources # source presence validation is handled in PG, as per accepts_nested_attributes constraints # validates_uniqueness_of :source_id, scope: [:project_id] before_destroy :check_for_use protected def check_for_use if source.citations.where(citations: {project: project_id}).any? errors.add(:base, 'Source can not be removed, it is used in this project') throw(:abort) end end end |
Instance Method Details
#check_for_use ⇒ Object (protected)
25 26 27 28 29 30 |
# File 'app/models/project_source.rb', line 25 def check_for_use if source.citations.where(citations: {project: project_id}).any? errors.add(:base, 'Source can not be removed, it is used in this project') throw(:abort) end end |