Use self.name for same-table relations

Personally reading the class name made me take some time to realize it
was a same-table relation.
This commit is contained in:
Javi Martín
2019-10-24 03:50:33 +02:00
parent 27ed26d6f2
commit 915e2792fc
2 changed files with 3 additions and 3 deletions

View File

@@ -12,8 +12,8 @@ class Budget
include Sanitizable include Sanitizable
belongs_to :budget belongs_to :budget
belongs_to :next_phase, class_name: "Budget::Phase" belongs_to :next_phase, class_name: self.name
has_one :prev_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id has_one :prev_phase, class_name: self.name, foreign_key: :next_phase_id
validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH } validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH }
validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH } validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH }

View File

@@ -8,7 +8,7 @@ class RelatedContent < ApplicationRecord
belongs_to :author, class_name: "User" belongs_to :author, class_name: "User"
belongs_to :parent_relationable, polymorphic: true, touch: true belongs_to :parent_relationable, polymorphic: true, touch: true
belongs_to :child_relationable, polymorphic: true, touch: true belongs_to :child_relationable, polymorphic: true, touch: true
has_one :opposite_related_content, class_name: "RelatedContent", foreign_key: :related_content_id has_one :opposite_related_content, class_name: self.name, foreign_key: :related_content_id
has_many :related_content_scores has_many :related_content_scores
validates :parent_relationable_id, presence: true validates :parent_relationable_id, presence: true