0
多くの装備を持つイベントを作成しています。私はEquipmentモデルを検証したいと思います。現在保存している機器のイベントにアクセスするにはどうすればよいですか?私は、機器が使用される日付を得るために必要です(日付はイベントモデルから知られています)。保存時にhas_many側に現在のオブジェクトを取得します
class Event < ApplicationRecord
has_many :equipment_events, class_name: EquipmentEvent
has_many :equipment, through: :equipment_events
end
class Equipment < ApplicationRecord
has_many :equipment_events
has_many :events, through: :equipment_events
validate :equipment_already_used
def equipment_already_used
date = # <== HERE I need the date from this equipment's event that I am saving
end
end