blob: f4a72f22c4a0b95edefa2d452239a47742e6e8f8 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 | class ReferentialSuite < ApplicationModel
  belongs_to :new, class_name: 'Referential'
  validate def validate_consistent_new
    return true if new_id.nil? || new.nil?
    return true if new.referential_suite_id == id
    errors.add(:inconsistent_new,
               I18n.t('referential_suites.errors.inconsistent_new', name: new.name))
  end
  belongs_to :current, class_name: 'Referential'
  validate def validate_consistent_current
    return true if current_id.nil? || current.nil?
    return true if current.referential_suite_id == id
    errors.add(:inconsistent_current,
               I18n.t('referential_suites.errors.inconsistent_current', name: current.name))
  end
  has_many :referentials, -> { order "created_at desc" }
end
 |